An Emotion Leak.

Goodbye, Clutter

Technology 14723

Do you often look for a file in your Downloads folder, wait for Windows to load the plethora of files in it, scan through the unorganized mess and wish that your files get miraculously get organized? Sigh, what a long sentence! But yeah you’ve been through it. I’ve been through it. Read along, thank me later.

It is a myth that computer programs are hard to write and languages like Python have proven it time and again. Python is a fun language to automate your day-to-day stuff and make your life easier. Today we’ll be seeing how to write a Python3 script that magically sorts your Downloads folder once in every two hours.


This is for those who want to just automate the organizing task. This code works for Windows, Linux and macOS users, but I’m going to show only how to set this up to run automatically on Windows. You’ll need Python 3.x version installed on your PC.


    Copy the above code snippet and save it to a file (say organize_downloads.pyw).

    Note: It is important that the file extension is pyw and not py

  2. Open your run menu (Win Key + R)

  3. Type shell:startup and press enter

  4. Right click anywhere on your window and choose New > Shortcut

  5. Enter the location to the script that you saved (say D:\organize_downloads.pyw)

  6. Give a name for the shortcut file and press Finish

  7. Restart your computer or sign out and sign back in

That’s it. Now the script starts running every time you open your computer and stays running in the background. Once in every two hours, the script checks your Downloads folder and organizes it.

Code Breakdown

  • The first few lines of the code imports the necessary packages for the script to run. All the packages comes pre-installed on a default Python installation

  • Then we find the location of the user directory and the downloads folder

  • The FILE_EXT_MAP is the place where the magic happens. It contains a dictionary of lists. The key to every dictionary will be a new directory where the list corresponding to defines the extensions of the files that will be put in it

  • TIME_INTERVAL defines the interval at which the script must check for files and organize them. The default is set to 7200 seconds (2 hours) but you can change it to your need

  • The next few lines of the defines the function which checks for the file’s extension and moves it to the corresponding directory based on the FILE_EXT_MAP

  • The if __name__ == ‘__main__’ block of the program is the main part of the program. It lists the files present in the downloads folder and passes it to the function we defined above

If you want the script only to be run when you wish to sort the downloads folder and not always then you can do the following:

  • You can skip the steps 2-7 completely

  • Remove the following lines of code

    • TIME_INTERVAL = 7200

    • while True:

    • time.sleep(TIME_INTERVAL)

Hope this helped you clean your downloads folder without breaking a sweat. You can also extend this concept to organize your Desktop which would be covered in a different post.

Leave a Reply

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

All rights reserved to Wanderersink