Automated Directory Cleanup

Project Overview

The purpose of this project was to create a way to automatically remove a large number of files while also preserving a specific subset of those files.


This program is configured by filling out config.ini with the desired values. It must comply with the following key-value format, where the keys, such as fol0, files0 may be named anything and the suffix values should not be contained in quotes. [Subfolders to Clean-Up] DOES NOT contain the top level directory you are cleaning out; that is specified in the command line argument when executing the program.

[Subfolders to Clean-Up]
fol0 = Test-Subdir0
fol1 = Test-Subdir1
fol2 = Test-Subdir2
[Files to Preserve Given Suffix]
files0 = .txt
files1 = .fastfcq

Running the Script

To use this program execute $ python3 COMMAND DIR_PATH, where DIR_PATH is the absolute path to the top level directory that will be cleaned up and COMMAND may be one of the following:

  • help: Displays available commands, this is the default if no arguments are provided.
  • check_files: Displays the files that will be preserved if the delete command is run. It is recommended to run this first and make sure that you are okay with the output.
  • delete_files: Deletes all of the files inside the subfolders listed in config.ini except for files ending with the same suffixes listed in config.ini


Checking if files will be preserved correctly:

$ python3 /home/grant/Test check_files
filepath0 will be preserved
filepath1 will be preserved

Executing file cleanup:

$ python3 /home/grant/Test delete_files
Are you ok with the files being preserved and ready to run clean-up? (y/n):y
Files have been deleted

Project Repo:

image source: