Organize files using batch file feature image

How to Organize Folder using Batch file in Windows 10?

Nowadays users are downloading many file types and folders from the internet and saving them in any folder or partition directly without organizing. Over the time that particular folder or Drive partition will become messy and unorganized. This made difficulties in finding any file from that folder or partition. Organizing these files manually will be a time-consuming task. So, in this post, I am going to teach you to Organize folder using the Batch file in Windows 10. You can create a batch file from the code below and move the batch file to any folder or Partition, then run it directly. Admin privileges not require. This batch file will create a folder based on the file extension and then move the files to the respective folder.  Let’s see how to create a Batch file to Organize your folder.

Organize Folder using Batch file in Windows 10:

First Create the batch file. Open the Run command by pressing Windows + R and type Notepad and hit enter.

Now copy-paste the below-mentioned script in the Notepad text Editor.

@echo off
for %%a in (".\*") do (
if "%%~xa" NEQ "" if "%%~dpxa" NEQ "%~dpx0" (
if not exist "%%~xa" mkdir "%%~xa"
move "%%a" "%%~dpa%%~xa\"
))

Save it to any location with the .bat file extension. I saved the batch file as File_Organizer.bat.

Now move the batch file to any folder or partition, then double click on the batch file and run it. After the execution, the files will be moved to their respective extension folders.

Before organizing
Organize Folder using Batch file after

Code Explanation:

for %%a in (“.\*”) do (

if “%%~xa” NEQ “” if “%%~dpxa” NEQ “%~dpx0” (

This line of code will check for an extension on Each file on the particular folder and if the extension is not there it will mark the file as a separate file.

if not exist “%%~xa” mkdir “%%~xa”

This line of code will create a extension folder and check the extension folder exists.

move “%%a” “%%~dpa%%~xa\”

This line of code will move the files to the respective directory.

You can use this batch file in system partitions, folders, External Hard Disk, and USB Pen Drive.

Also Read: How to Add Kali Linux to Windows Terminal Profile?

2 thoughts on “How to Organize Folder using Batch file in Windows 10?”

  1. I ran the batch file. It worked great, but when I ran it in a folder with different file types plus some subfolders, all the file disappeared and only the subfolders and batch file remained. Where did the files go?

  2. UPDATE!

    I can still find the missing files by searching for them and can be opened.

    And the path shows that the file is in the folder where they dissapeared from.

    I tried ‘show hidden files’, but nothing came up. I also checked if I could see the files in CMD, but no.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top