Automatically Create Folders and Sort Files Based on Extension in Windows

In this Windows tutorial, we will show you the steps to automatically create folders and sort files based on their extension type. Just make a one-stop visit to your PC’s Download folder and you would be greeted with a plethora of files scattered all over. This usually translates to quite a few issues in itself. Not only does it tends to disrupt the UI/UX flow, but the ease of user experience takes a back seat as well. Well, even searching for a specific file seems like finding a needle in the haystack.

To help you out in this regard, Windows has baked in the Sort by and Group By options in its right-click menu. However, that doesn’t spell out a clutter-free environment as all the files would still be present under the same folder. To counter this, I compiled a few lines of codes for your Windows PC that will automatically create folders and sort files based on their extension type.

automatically create folder and sort files in windows

For example, if you have 3 IMG files, 2 PNG files, 2 TXT Files, and 4 EXE files, then my command will create an IMG folder and send all the IMG files to that folder, create a PNG folder and send all the PNG files inside that folder and so on. All this is possible just via a single mouse click. Sounds impressive, right? So without any further ado, let’s check out how this could be achieved.

How to Automatically Create Folders and Sort Files Based on Extension in Windows

This guide outlines two different approaches to carry out the aforementioned task. The first is the Shortcut Method where I have provided the command file. You only need to open that file once and the rest will be taken care of by it. However, if you wish to challenge your inner geek and want to create the command file on your own, then the second method is just for you.

The Shorter Approach

  1. To begin with, download the droidwinsort.zip file and extract it onto your PC.
    droidwinsort file
  2. You shall get the drodwinsort.bat file, transfer it to the folder where you need to carry out the automatic sorting.
  3. Finally, run that .bat file. All the files will automatically be organized within their respective folders in a matter of seconds.

That’s it! This is the simplest and easiest method to automatically create folders and sort files based on their extension type in Windows. However, if you want to get hold of the command that did this job, then hop onto the manual approach given below.

The Manual Method

  1. As before, head over to the desired folder where the sorting needs to be done.
  2. Then right-click in an empty location inside that folder and create a new Text Document.
  3. Now copy-paste the below command in that Notepad file:
    @echo off
    
    rem For each file in your folder
    for %%a in (".\*") do (
    rem check if the file has an extension and if it is not our script
    if "%%~xa" NEQ "" if "%%~dpxa" NEQ "%~dpx0" (
    rem check if extension folder exists, if not it is created
    if not exist "%%~xa" mkdir "%%~xa"
    rem Move the file to directory
    move "%%a" "%%~dpa%%~xa\"
    ))

  4. Go to File > Save As and change the Save As Type to All Files.
  5. Then type in droidwinsort.bat under the Filename section and hit Save.
  6. Finally, run this file and the sorting will be done under their respective folders in no time whatsoever!

So with this, we round off the guide on how you could automatically create folders and sort files based on their extension type in Windows. We have shared both the manual as well as the shortcut way of carrying out this task. With that said, if you have any queries concerning the aforementioned steps, do let us know in the comments. We will get back to you with a solution at the earliest.


Share: