How to Organize Files Automatically Using a Batch Script

Are you tired of your cluttered folders filled with hundreds of files? Do you spend precious time searching for specific documents, images, or videos because everything is mixed together? Say goodbye to the chaos! With this simple yet powerful batch script, you can automatically organize your files by their type, transforming any messy folder into a clean, well-structured space that’s easy to navigate.

What the Script Does

This batch script will:

How to Use the Script

  1. Copy the script below into a text editor like Notepad.
  2. Save the file as FileOrganizer.bat (ensure the file extension is .bat, not .txt).
  3. Place the .bat file into the folder you want to organize (e.g., your Documents, Pictures, or Music folder).
  4. Double-click the .bat file to run it.

Batch Script Code

@echo off
setlocal enabledelayedexpansion

:: Loop through all files in the current directory
for %%f in (*.*) do (
    set "ext=%%~xf"
    set "ext=!ext:~1!"  :: Remove the dot from the extension

    :: Skip if the file has no extension
    if not "!ext!"=="" (
        :: Create a folder for the extension if it doesn't exist
        if not exist "!ext!" (
            mkdir "!ext!"
        )

        :: Move the file to the corresponding folder
        move "%%f" "!ext!\"
    )
)

echo Files have been organized!
pause

Example

Before running the script:

MyFolder/
├── vacation.jpg
├── report.pdf
├── presentation.pptx
├── song.mp3
├── design.psd

After running the script:

MyFolder/
├── JPG/
│   └── vacation.jpg
├── PDF/
│   └── report.pdf
├── PPTX/
│   └── presentation.pptx
├── MP3/
│   └── song.mp3
├── PSD/
│   └── design.psd

Note: Always back up your files before running the script, just in case. This script only organizes files in the current directory and does not affect subfolders.

Why You’ll Love It

Download the Script

If you’d like to download the script instead of copying it, click the button below:

Download FileOrganizer.bat