Skip to content

How to Create a Batch File to Sort Files in Downloads Folder

Let’s not hide from the fact that the Downloads folder on our PC is probably the most disorganized one. Every day or other, files get randomly scattered throughout the folder, no matter how well you organize them. To counter this issue, I created a simple Windows batch file that will sort files in the Downloads folder that contains all your downloaded files into its respective folders.

For example, suppose you have a bunch of JPG, PNG, HTML, TXT and PDF files. On executing the batch file, 5 different folders pertaining to the above file extensions will be created and the files will automatically be moved to their respective folders. And all this will take only a couple of seconds. With that said, here are the steps to create a batch file and sort your Downloads folder. Also, check out these handy Windows Command Prompt tricks to use it like a pro.

Create a Batch File and Sort your Downloads

batch sort file in folder

Dsort is the Batch file that sorted the Downloads folder

Batch Files are a handy way of doing things. If you are regularly into doing any particular task, then rather than repeating the same steps over and over again, you could create a batch file and simply execute it. In other cases, a batch file is also used if you wish to execute numerous lines of codes at one go, as is the case while entering fastboot commands for flashing the stock firmware.

With that, you might have got the general concept of these batch files. Let’s now have a look at the steps to create a Batch file and effectively sort your Downloads folder. Do note that the codes that I am about to give aren’t only limited to the Downloads folder. You could execute this batch file anywhere on your PC, inside any folder you want. Just make sure to move the batch file inside the folder that needs to be sorted out. If you want to view saved Wi-Fi passwords on your Windows PC, you can do that using commands.

Steps to Create a Batch File

  1. Head over to the folder where you wish to arrange the files.
  2. Right-click in an empty space and create a new text document.
    new text document windows
  3. Enter the following codes in the text file. These lines of code inside the batch file will help in sorting your Downloads folder.
    @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\"
    batch file code
  4. Now save this file by giving it any name of your choice but make sure to keep the extension as .bat (which is the default extension of a batch file). In this guide, we have named it dsort (i.e. Downloads Sort) Also, change the ‘Save as type‘ to All Files (*,*).
    save dsort batch file
  5. Finally, execute this batch file. Within seconds, the batch file will create different folders and then move the files into its respective folders.
    batch file created

That is it. These were the steps to create a Batch file and sort Downloads folder on your PC. Do let us know in the comments, what do you think of this useful tip.

Read Next: How to  Enable God Mode, Watch Star Wars in CMD

2 thoughts on “How to Create a Batch File to Sort Files in Downloads Folder”

  1. Hi, Can you modify it to rename the file with _1, or _2 if same file name already exists.
    or if same file name with same size exists. replace,
    else add _1, or _2 in the file end of name

    I tried a lot, but I have zero knowledge of batch files.

Leave a Reply

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.