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.

Configuration

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 file-cleanup.py 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

Examples

Checking if files will be preserved correctly:

$ python3 file-cleanup.py /home/grant/Test check_files
filepath0 will be preserved
filepath1 will be preserved
...

Executing file cleanup:

$ python3 file-cleanup.py /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: https://github.com/Novota15/Automated-Directory-Cleanup

image source: https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.iconfinder.com%2Ficons%2F4051658%2Fcleaning_data_data_cleaning_data_cleansing_data_validation_database_file_icon&psig=AOvVaw0IctjWKQW2TjZCJBLPWouF&ust=1584760514528000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCNCS6pKLqOgCFQAAAAAdAAAAABAd

Top