A chronological folder backup script for those who want flexibility.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

import os
import shutil
class Excluder:
Handles the deletion of files or directories from a specified source path.
First off, read the f--king README. Second, this will permanently delete the
specified files and directories from any subdirectory of the folder you provide
when you instantiate Chronos. Consider that you will delete ALL occurances of ANY
file OR directory you give this class. You have been sufficiently warned.
path: string
The source path.
excluded_files: list
A list of filenames to delete if found in the walk.
excluded_dirs: list
A list of directory names to delete if found in the walk.
def __init__(self, excluded_files, excluded_dirs):
self.excluded_files = excluded_files
self.excluded_dirs = excluded_dirs
self._deleted = []
self.path = None
def _parse_files(self, root, files):
for file in files:
path = os.path.join(root, file)
if file in self.excluded_files:
def _parse_dirs(self, root, dirs):
for dir in dirs:
path = os.path.join(root, dir)
if dir in self.excluded_dirs:
def _walk(self):
for root, dirs, files in os.walk(self.path):
self._parse_files(root, files)
self._parse_dirs(root, dirs)
def _report(self):
for item in self._deleted:
print(f'Deleted: {item}')
def __call__(self, path):
self.path = path