CleanPy – Python Script to Organize Your Files

Share this post:
Prashant Sengar Github
Github

I am a pretty good organizer of files, in the beginning. As time passes, I just keep hoarding them until I cannot find files which I really require urgently. What is the best way to clean your PC? The best way is to first organize different files in folders which help you to identify which files to remove and which files to keep. This is exactly what CleanPy does.

This is the script which got the best response in Kharagpur Winter of Code and also got me the most messages which were thankful that this existed. So I guess it really is something that people want.

It has two mode, hard and soft mode for organizing files. Soft mode only organizes the files which are in the current directory. In hard mode, CleanPy organizes all the files in immediate directory and its sub-directories. So, in case you wanted to run it in the root directory, don’t.

Features:

There isn’t a lot of features to write here. Just run the script in your directory and it will create sub-directories with the files moved to their respective directories. For example, all PDF files will be moved to a sub-directory pPDF. All audio files (.mp3, .wav, etc) will be moved to pAudios and similarly for other files.

It currently moves audio files, video files, document formats (xlsx, docx, etc), application files (.exe), videos (.mp4, .flv etc) and image files.

The reason why the folders are created with a ‘p’ suffix is because I wanted all these folders to be at the same place if the files are sorted alphabetically so that you can find all the files easily. ‘p’ is chosen because I couldn’t find a letter better than the my first name initial.

How to use:

  • Clone the repo from Github
  • Run the script by calling python3 arrange.py
  • You will then be asked to choose between hard and soft mode.

How it works:

The working is pretty simple. I just have to walk through the directory (and subdirectories in case of hard mode) and identify the file type based on the extension and then move them to the required destination directories.

It creates only those directories now which have at least one file. So no more unnecessary folder creation. It also saves all these sub-directories under a single sub0directory called CleanedPy

To do:

A lot has to be done to make this even better. Currently, it is pretty basic but I want to improve it so that it is useful to more people.

  1. Make it more interactive and configurable. Let people choose which directories they want to create and which files they want to move.
  2. Make a package to install and run anywhere from console
Share this post:

1 thought on “CleanPy – Python Script to Organize Your Files”

  1. Pingback: Looking Back — 2019-20 – Prashant Sengar

Leave a Comment

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