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 many JPG, PNG, HTML, TXT, and PDF files. On executing the batch file, 5 different folders about the above 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.

Table of Content

Create a Batch File and Sort your Downloads

batch sort file in folder
Dsort is the Batch file that sorts 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, you could create a batch file and 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 look at the steps to create a Batch file and effectively sort your Downloads folder. You can execute this batch file anywhere on your PC, inside any folder you want. Just 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 area 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 keep the extension as .bat (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 the Downloads folder on your PC. Do let us know in the comments, what you think of this useful tip.

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

Was this Article helpful?
YesNo