Goodbye, Clutter

By Pranav Sricharan

December 19, 2018

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.

TL;DR

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.

  1. https://gist.github.com/pranavsricharan/33d88f3a2789aacd998b9c8a9041ef20

    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.

Tags: , , , ,

About Pranav Sricharan

Linux Geek | Tech Enthusiast | Graphic Designer

6 thoughts on “Goodbye, Clutter

  1. I simply want to mention I’m all new to blogging and definitely loved your website. Likely I’m planning to bookmark your site . You definitely have fabulous well written articles. Appreciate it for sharing your blog site.

  2. Thanks for your article. It is extremely unfortunate that over the last decade, the travel industry has already been able to to tackle terrorism, SARS, tsunamis, flu virus, swine flu, along with the first ever real global economic depression. Through it the industry has proven to be robust, resilient as well as dynamic, finding new solutions to deal with hardship. There are usually fresh issues and opportunities to which the industry must once more adapt and act in response.

Leave a Reply

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