import os
import shutil
import sys
from time import sleep
from pathlib import Path
#Dictionnaire
DIRECTORIES = {
"HTML": [".html5", ".html", ".htm", ".xhtml"],
"IMAGES": [".jpeg", ".jpg", ".tiff", ".gif", ".bmp", ".png", ".bpg", "svg",
".heif", ".psd"],
"VIDEOS": [".avi", ".flv", ".wmv", ".mov", ".mp4", ".webm", ".vob", ".mng",
".qt", ".mpg", ".mpeg", ".3gp", ".mkv"],
"DOCUMENTS": [".oxps", ".epub", ".pages", ".docx", ".doc", ".fdf", ".ods",
".odt", ".pwi", ".xsn", ".xps", ".dotx", ".docm", ".dox",
".rvg", ".rtf", ".rtfd", ".wpd", ".xls", ".xlsx", ".ppt",
"pptx"],
"ARCHIVES": [".a", ".ar", ".cpio", ".iso", ".tar", ".gz", ".rz", ".7z",
".dmg", ".rar", ".xar", ".zip"],
"AUDIO": [".aac", ".aa", ".aac", ".dvf", ".m4a", ".m4b", ".m4p", ".mp3",
".msv", "ogg", "oga", ".raw", ".vox", ".wav", ".wma"],
"PLAINTEXT": [".txt", ".in", ".out"],
"PDF": [".pdf"],
"PYTHON": [".py"],
"XML": [".xml"],
"EXE": [".exe"],
"SHELL": [".sh"]
}
def type(text):
words = text
for char in words:
sleep(0.000001)
sys.stdout.write(char)
sys.stdout.flush()
def type2(text):
words = text
for char in words:
sleep(0.03)
sys.stdout.write(char)
sys.stdout.flush()
currentUser = os.getlogin()
type('''
──────────────────────────────────────────────
─██████████████─██████████████─██████████████─
─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░░░░░░░░░██─
─██░░██████░░██─██░░██████████─██░░██████░░██─
─██░░██──██░░██─██░░██─────────██░░██──██░░██─
─██░░██████░░██─██░░██████████─██░░██──██░░██─
─██░░░░░░░░░░██─██░░░░░░░░░░██─██░░██──██░░██─
─██░░██████░░██─██░░██████████─██░░██──██░░██─
─██░░██──██░░██─██░░██─────────██░░██──██░░██─
─██░░██──██░░██─██░░██─────────██░░██████░░██─
─██░░██──██░░██─██░░██─────────██░░░░░░░░░░██─
─██████──██████─██████─────────██████████████─
──────────────────────────────────────────────\n''')
sleep(1)
type2(f'Hi {currentUser}!\n')
type2(f'Welcome to AFO, (Automatic File Organizer).\n')
type2('Thought and coded by [email protected]\n')
sleep(2)
type('──────────────────────────────────────────────\n')
sleep(0.3)
type2('What do you want to organize? <:\n')
type2('Downloads [1]\n')
type2('Documents [2]\n')
type2('Help & Details [3]\n')
sleep(0.3)
answer = input('> ')
type('──────────────────────────────────────────────\n')
answered = True
def AFOdocuments():
type2('Checking if directories exist.....\n')
sleep(1)
#Documents folder
os.chdir('C:/Users/{currentUser}/Documents/')
FILE_FORMATS = {file_format: directory
for directory, file_formats in DIRECTORIES.items()
for file_format in file_formats}
# This will organise your files
def organize():
for entry in os.scandir():
if entry.is_dir():
continue
file_path = Path(entry.name)
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))
# if extension not present in the dctionary than create a folder name "OTHER"
try:
os.mkdir("OTHER")
except:
pass
for dir in os.scandir():
try:
if dir.is_dir():
os.rmdir(dir)
else:
os.rename(os.getcwd() + '/' + str(Path(dir)), os.getcwd() + '/OTHER/' + str(Path(dir)))
except:
pass
if __name__ == "__main__":
organize()
type2('Moving files.\n')
sleep(1)
type2('──────────────────────────────────────────────\n')
def AFOdownload():
type2('Checking if directories exist.....\n')
sleep(1)
# Download Folder
os.chdir('C:/Users/{currentUser}/Downloads/')
FILE_FORMATS = {file_format: directory
for directory, file_formats in DIRECTORIES.items()
for file_format in file_formats}
# This will organise your files
def organize():
for entry in os.scandir():
if entry.is_dir():
continue
file_path = Path(entry.name)
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))
# if extension not present in the dctionary than create a folder name "OTHER"
try:
os.mkdir("OTHER")
except:
pass
for dir in os.scandir():
try:
if dir.is_dir():
os.rmdir(dir)
else:
os.rename(os.getcwd() + '/' + str(Path(dir)), os.getcwd() + '/OTHER/' + str(Path(dir)))
except:
pass
if __name__ == "__main__":
organize()
type2('Moving files.\n')
sleep(1)
type2('──────────────────────────────────────────────\n')
while answered == True:
if answer == '1':
answered = False
AFOdownload()
elif answer == '2':
answered = False
AFOdocuments()
elif answer == '3':
type2('AFO will create folders on a previously selected path [1] for your Downloads path and [2] for your Documents path. It will use the folders to move files into them depending on their extensions.\n')
sleep(1.5)
type2('A little example; a .txt or a doc file will be moved in a folder called TXT_FILES. A .mp4 or m4v file will be moved in a folder called VIDEOS and it goes on.\n')
sleep(1.5)
type2('Now that you understood, please choose an option below.\n')
sleep(1.5)
type2('What do you want to organize? <:\n')
type2('Downloads [1]\n')
type2('Documents [2]\n')
type2('Help & Details [3]\n')
sleep(0.3)
answer = int(input('> '))
type('──────────────────────────────────────────────\n')
else:
type2("Woops I didn't get it, it looks like an invalid answer!\n")
sleep(1)
type2('if you think this was a bug, please report it at [email protected].\n')
sleep(0.7)
type2("Please try again.\n")
sleep(1.5)
type2('What do you want to organize? <:\n')
type2('Downloads [1]\n')
type2('Documents [2]\n')
type2('Help & Details [3]\n')
sleep(0.3)
answer = input('> ')
type('──────────────────────────────────────────────\n')
type('──────────────────────────────────────────────\n')
type2('AFO has been executed successfully without errors.\n')
sleep(1.5)
type2('Closing program.')
sleep(1.5)