From 98ff3a806d52436b8a44b553d0f021ac50af336a Mon Sep 17 00:00:00 2001 From: Ayush yadav <83113106+sysoutayush@users.noreply.github.com> Date: Mon, 18 Oct 2021 12:54:47 +0530 Subject: [PATCH] Create filecleanr.py --- python codes/filecleanr.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 python codes/filecleanr.py diff --git a/python codes/filecleanr.py b/python codes/filecleanr.py new file mode 100644 index 00000000..06fd6ca2 --- /dev/null +++ b/python codes/filecleanr.py @@ -0,0 +1,16 @@ +def organize_junk(): + for entry in os.scandir(): + if entry.is_dir(): + continue + file_path = Path(entry) + file_format = file_path.suffix.lower() + if file_format in FILE_FORMATS: + directory_path = Path(FILE_FORMATS[file_format]) + directory_path.mkdir(exist_ok=True) + file_path.rename(directory_path.joinpath(file_path)) + + for dir in os.scandir(): + try: + os.rmdir(dir) + except: + pass