Bernard Aybouts - Blog - Miltonmarketing.com

Approx. read time: 4.6 min.

Post: Scripted Harmony: Automating File Sorting into Named Folders

To use the “Scripted Harmony: Automating File Sorting into Named Folders” program, start by placing the batch script in the folder containing the files you wish to organize. This script is designed to be flexible, allowing you to either organize all files within the directory or focus specifically on files with a particular extension. For general use, simply double-click the batch file to execute it, and it will automatically create new folders named after each file (excluding the file extension) and move the files into their respective folders. This process tidies up your directory, making it easier to navigate and manage your files.

If you want to organize files by a specific extension, run the script through a command prompt window. Open the command prompt, navigate to the directory where the script and your files are located, and then type the name of the batch file followed by the extension you’re interested in organizing, like so: `OrganizeFiles.bat txt` for text files. The script will then provide a preview of the action it will perform, such as showing an example file and the folder it will be moved into, and ask for your confirmation to proceed. Confirm to start the organization process, or cancel if you change your mind. This intuitive script offers a straightforward solution to declutter your digital workspace efficiently.

[wpdm_package id=’23275′]

Here is the code to the batch script your downloading. Step by step explanation. You can edit and view the code that’s running. Its safe.

Copy to Clipboard

Determine File Extension to Process

set "ext=*.*"

This sets a variable ext with the value *.*, which means all files.

The following if statement checks if the first command-line argument (%~1) is not empty:

  • If it’s not empty, the script updates ext to target files with the specified extension and prints a message about looking for files with that extension:
    set "ext=*.%~1"
    echo Looking for files with the '.%~1' extension...
  • If it is empty, it prints a message indicating it’s looking for all files:
    echo Looking for all files...

Check for Files to Process, Excluding the Script Itself

set "filesFound=false"
set "exampleFile="

Initializes filesFound to false and exampleFile to an empty string.

Uses a for loop to iterate over all files matching the extension defined in ext:

for %%F in (%ext%) do (
    if "%%~fF" neq "%~f0" (
        set "filesFound=true"
        if not defined exampleFile set "exampleFile=%%F"
    )
)

Inside the loop, it checks if the file being processed (%%F) is not the script itself (%~f0). If true:

  • Sets filesFound to true.
  • If exampleFile is not defined, sets it to the current file (%%F). This captures the first file that is not the script.

If No Files Found, Explain Usage and Exit

Checks if no files were found (filesFound remains false):

if "!filesFound!"=="false" (
    echo No files found to organize. Here's how you can use this script:
    echo -------------------------------------------------------------------------
    echo - Place this script in a folder with files you want to organize.
    echo - Run it without arguments to organize all files, or with an extension to focus on those files.
    echo   Example to organize only text files: %~nx0 txt
    echo -------------------------------------------------------------------------
    pause
    exit /b
)

If true, prints instructions on how to use the script and then pauses and exits the script.

Show an Example of What Will Happen

If exampleFile is defined (i.e., there is at least one file to process):

set "exampleName=!exampleFile:~0,-4!"
echo For example, if we have a file named '!exampleFile!', it will be moved into a folder named '!exampleName!'.

Prints a message showing what will happen to exampleFile — it will be moved into a folder named after itself minus the extension.

Ask for User Confirmation to Proceed

Prints a prompt asking if the user wants to continue with the operation:

echo.
echo This script will now start organizing files in the same manner as shown.
echo Do you want to continue with this operation? (Y/N)
set /p userChoice=
if /i not "%userChoice%"=="Y" (
    echo Operation cancelled by the user. No changes have been made.
    pause
    exit /b
)

Reads the user’s choice. If the choice is not ‘Y’ (case-insensitively), it cancels the operation, informs the user, and exits.

Main Loop for Organizing Files

If the user confirms to proceed, it enters another for loop over the files:

for %%F in (%ext%) do (
    if "%%~fF" neq "%~f0" (
        set "fileName=%%~nF"
        set "dirName=%%~nF"

        :: Create directory if it does not exist
        if not exist "!dirName!" (
            echo Creating folder: !dirName!
            mkdir "!dirName!"
        )
        
        :: Move the file into its new folder
        echo Organizing: %%F
        move "%%F" "!dirName!"
    )
)

Checks again if the current file is not the script. Sets fileName and dirName to the name of the file (without the extension). Checks if a directory with the name of the file doesn’t exist. If it doesn’t, creates the directory. Moves the file into the newly created directory and prints a message indicating the operation.

Completion Message

After all files have been processed, prints a message indicating that the organization is complete and then pauses.

The Longevity Blueprint: AI-Powered Health Optimization

Current step:1AI-Human Medical Analyzer: Smarter, Personalized Health
2AI-Human Medical Analyzer: Smarter, Personalized Health

> SYS.HEALTH: AI-Human Medical Analyzer_

// Revolutionize Your Diagnostics

Experience the perfect blend of cutting-edge AI precision and expert human care. Our revolutionary analyzer turns your raw health data into personalized, actionable insights tailored just for you.

> INITIALIZING_BIOMETRIC_SCAN...

[+] DATA_INPUT

Securely upload complex health parameters, including lab bloodwork and comprehensive medical history.

[+] PROCESSING

Advanced algorithmic parsing combined with human-level oversight ensures hyper-accurate data interpretation.

[+] OUTPUT_MATRIX

Receive smarter, faster, and truly personalized care strategies to take immediate charge of your health journey.

A name/nickname is required to continue.

> TRANSLATION_MATRIX_ACTIVE...
[ LANG_EN ]
Knowledge Heals, Prevention Protects
[ LANG_HI ]
ज्ञान ठीक करता है, रोकथाम सुरक्षा करती है
[ LANG_ZH ]
知识治愈,预防保护
[ LANG_JA ]
知識は癒し、予防は守る
[ LANG_HE ]
הידע מרפא, המניעה מגנה
[ LANG_AR ]
المعرفة تُشفي، والوقاية تحمي
[ LANG_FR ]
La connaissance guérit, la prévention protège

> SYS.AUTH: Data Processing Consent_

[ AWAITING_AUTHORIZATION ] By providing consent, you allow us to process your uploaded data through our proprietary AI-Human analysis system.

  • [+] SECURE_REVIEW: This ensures your information is carefully reviewed using advanced AI technology and certified professional oversight to deliver personalized health insights.
  • [+] PRIVACY_LOCK: Your privacy is our strict priority. Your data will only be used for this specific diagnostic purpose.

> SYS.UPLOAD: Share Medical Records [OPTIONAL]_

[ USER_CONTROL_ACTIVE ] Uploading your medical records during registration is entirely optional. You can choose to bypass this step and provide data later if it suits your timeline.

You dictate the data flow: share as much or as little as you’re comfortable with, and let us guide you toward better health.

[+] FORMAT_SUPPORT

We accept all file formats, including photos, PDFs, text documents, and raw official medical data.

[+] DATA_YIELD

Increased inputs correlate with higher precision. The more info you share, the better we tailor your personalized insights.

> NEXT_STEPS: Post-Registration Protocol_

Once your registration is complete, a human specialist from our team will personally reach out to you within 3-10 business days. We will discuss your health journey and map out exactly how we can support you.

About the Author: Bernard Aybout (Virii8)

Avatar Of Bernard Aybout (Virii8)
I am a dedicated technology enthusiast with over 45 years of life experience, passionate about computers, AI, emerging technologies, and their real-world impact. As the founder of my personal blog, MiltonMarketing.com, I explore how AI, health tech, engineering, finance, and other advanced fields leverage innovation—not as a replacement for human expertise, but as a tool to enhance it. My focus is on bridging the gap between cutting-edge technology and practical applications, ensuring ethical, responsible, and transformative use across industries. MiltonMarketing.com is more than just a tech blog—it's a growing platform for expert insights. We welcome qualified writers and industry professionals from IT, AI, healthcare, engineering, HVAC, automotive, finance, and beyond to contribute their knowledge. If you have expertise to share in how AI and technology shape industries while complementing human skills, join us in driving meaningful conversations about the future of innovation. 🚀