Skip to content

Instantly share code, notes, and snippets.

@jonathanfelicity
Last active May 7, 2022 18:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanfelicity/e47838475d0d092e7733e89a7774bdc0 to your computer and use it in GitHub Desktop.
Save jonathanfelicity/e47838475d0d092e7733e89a7774bdc0 to your computer and use it in GitHub Desktop.
Arranging and Cleaning files with python
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