Skip to content

Instantly share code, notes, and snippets.

@harendra21
Created January 11, 2022 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harendra21/29d2b8b82cfb8cfae6d1d8be10e0ce2e to your computer and use it in GitHub Desktop.
Save harendra21/29d2b8b82cfb8cfae6d1d8be10e0ce2e to your computer and use it in GitHub Desktop.
import os
import glob
import shutil
from os import path
filename=glob.glob("/path/to/folder/*")
documents=['.pdf','.docx','.doc','.txt','.csv','.xlsx','.sql','.json']
pictures=['.jpeg','.jpg','.svg','.png','.PNG','.gif']
videos=['.mp4','.avi','.webm']
music=['.mp3']
setupFiles=['.exe','.msi','.deb']
compressedFiles=['.zip','.tgz']
DocumentsLocation='/path/to/folder/Documents'
picturesLocation='/path/to/folder/Pictures'
musicLocation='/path/to/folder/Music'
videosLocation='/path/to/folder/Videos'
setupFilesLocation='/path/to/folder/Programs'
compressedFilesLocation='/path/to/folder/Compressed'
for file in filename:
if os.path.splitext(file)[1] in documents:
if(path.exists(DocumentsLocation)):
shutil.move(file,DocumentsLocation)
else:
os.mkdir(DocumentsLocation)
shutil.move(file,DocumentsLocation)
if os.path.splitext(file)[1] in setupFiles:
if(path.exists(setupFilesLocation)):
shutil.move(file,setupFilesLocation)
else:
os.mkdir(setupFilesLocation)
shutil.move(file,setupFilesLocation)
if os.path.splitext(file)[1] in compressedFiles:
if(path.exists(compressedFilesLocation)):
shutil.move(file,compressedFilesLocation)
else:
os.mkdir(compressedFilesLocation)
shutil.move(file,compressedFilesLocation)
if os.path.splitext(file)[1] in pictures:
if(path.exists(picturesLocation)):
shutil.move(file,picturesLocation)
else:
os.mkdir(picturesLocation)
shutil.move(file,picturesLocation)
if os.path.splitext(file)[1] in videos:
if(path.exists(videosLocation)):
shutil.move(file,videosLocation)
else:
os.mkdir(videosLocation)
shutil.move(file,videosLocation)
if os.path.splitext(file)[1] in music:
if(path.exists(musicLocation)):
shutil.move(file,musicLocation)
else:
os.mkdir(musicLocation)
shutil.move(file,musicLocation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment