So this is probably the first coding tutorial that I am doing on this blog so make sure to give this a like. Anyways, let's build a program in Python that will automatically sort all of our files. Additionally, it will also have the functionality to remove duplicate files.
First, let's define the categories to sort our files. For this example, I chose 6 categories, images, videos, audio, documents, zips, and apps. You can add more if you wish.
In the variables listed below you want to copy and paste the directories of the corresponding folder that you want the file to end up in. For example, you can set the dest_dir_music to be a folder where you store music. Now keep in mind that the source_dir variable is the directory that you want to sort not where your sorted files will end up.
Now as you can see above, we need to list out all of the extensions of the files to categorize them. If a file ends with a certain extension, our program will know how to categorize it.
Next, let's get onto the function that actually sorts the files.
The code is pretty simple it has 3 parameters destination, entry, and file name. It checks if that file exists in the destination. If yes it then renames it to something else and then moves the file to the destination.
This program offers you an effective solution to automatically sort your files and eliminate duplicates, helping you save time and maintain tidy directories. This script improves your file management process by organizing files according to their extensions and making sure that duplicate files are renamed correctly. You can enhance it further by incorporating additional categories or adjusting the logic to suit your particular requirements.
I trust this tutorial was useful! If you found it helpful, be sure to like and share it. Keep an eye out for additional coding tutorials, and enjoy coding!
Comments