with this script, you can organize your files in the working folder based on their type.
import os
from pathlib import Path
SUBDIRECTORIES = {
"DOCUMENTS": ['.pdf','.rtf','.txt'],
"AUDIO": ['.m4a','.m4b','.mp3'],
"VIDEOS": ['.mov','.avi','.mp4'],
"IMAGES": ['.jpg','.jpeg','.png']
}
def pickDirectory(value):
for category, suffixes in SUBDIRECTORIES.items():
for suffix in suffixes:
if suffix == value:
return category
return 'MISC'
def organizeDirectory():
for item in os.scandir():
if item.is_dir():
continue
filePath = Path(item)
filetype = filePath.suffix.lower()
directory = pickDirectory(filetype)
directoryPath = Path(directory)
if directoryPath.is_dir() != True:
directoryPath.mkdir()
filePath.rename(directoryPath.joinpath(filePath))
organizeDirectory()