Last active
May 7, 2022 18:47
-
-
Save jonathanfelicity/e47838475d0d092e7733e89a7774bdc0 to your computer and use it in GitHub Desktop.
Arranging and Cleaning files with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
class Clean: | |
def __init__(self, fileExtention, fileFolder): | |
self.fileExtention = fileExtention; | |
self.fileFolder = fileFolder; | |
@attribute | |
def arrange(self): | |
for files in os.listdir('.'): | |
if files.endswith(self.fileExtention): | |
if os.path.exists(self.fileFolder) == True: | |
shutil.move(files, self.fileFolder) | |
else: | |
os.mkdir(self.fileFolder) | |
shutil.move(files, self.fileFolder) | |
else: | |
pass | |
img = Clean(('.png', 'jpg', 'icon'), 'images') | |
doc = Clean(('.epub', 'pdf', 'txt'), 'documents') | |
arc = Clean(('zip', '.rar'), 'archievs') | |
vid = Clean(('.mp4', '.avi'), 'videos') | |
img.arrange | |
doc.arrange | |
arc.arrange | |
vid.arrange |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment