|
| 1 | + |
| 2 | +import os |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +DIRECTORIES = { |
| 6 | + "HTML": [".html5", ".html", ".htm", ".xhtml"], |
| 7 | + "IMAGES": [".jpeg", ".jpg", ".tiff", ".gif", ".bmp", ".png", ".bpg", "svg", |
| 8 | + ".heif", ".psd"], |
| 9 | + "VIDEOS": [".avi", ".flv", ".wmv", ".mov", ".mp4", ".webm", ".vob", ".mng", |
| 10 | + ".qt", ".mpg", ".mpeg", ".3gp", ".mkv"], |
| 11 | + "DOCUMENTS": [".oxps", ".epub", ".pages", ".docx", ".doc", ".fdf", ".ods", |
| 12 | + ".odt", ".pwi", ".xsn", ".xps", ".dotx", ".docm", ".dox", |
| 13 | + ".rvg", ".rtf", ".rtfd", ".wpd", ".xls", ".xlsx", ".ppt", |
| 14 | + ".pptx", ".sql"], |
| 15 | + "ARCHIVES": [".a", ".ar", ".cpio", ".iso", ".tar", ".gz", ".rz", ".7z", |
| 16 | + ".dmg", ".rar", ".xar", ".zip"], |
| 17 | + "AUDIO": [".aac", ".aa", ".aac", ".dvf", ".m4a", ".m4b", ".m4p", ".mp3", |
| 18 | + ".msv", "ogg", "oga", ".raw", ".vox", ".wav", ".wma"], |
| 19 | + "PLAINTEXT": [".txt", ".in", ".out"], |
| 20 | + "PDF": [".pdf"], |
| 21 | + "PYTHON": [".py"], |
| 22 | + "XML": [".xml"], |
| 23 | + "EXE": [".exe"], |
| 24 | + "SHELL": [".sh"] |
| 25 | + |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +FILE_FORMATS = {file_format: directory |
| 30 | + for directory, file_formats in DIRECTORIES.items() |
| 31 | + for file_format in file_formats} |
| 32 | + |
| 33 | + |
| 34 | +def organize_junk(): |
| 35 | + for entry in os.scandir(): |
| 36 | + if entry.is_dir(): |
| 37 | + continue |
| 38 | + file_path = Path(entry.name) |
| 39 | + file_format = file_path.suffix.lower() |
| 40 | + if file_format in FILE_FORMATS: |
| 41 | + print(entry.name+" ongoing...") |
| 42 | + directory_path = Path(FILE_FORMATS[file_format]) |
| 43 | + if "bill" in str(file_path) or "Bill" in str(file_path): |
| 44 | + directory_path = Path("BILLS") |
| 45 | + directory_path.mkdir(exist_ok=True) |
| 46 | + if os.path.exists(str(directory_path.joinpath(file_path))): |
| 47 | + dirs = str(directory_path.joinpath(file_path)) |
| 48 | + while os.path.exists(dirs): |
| 49 | + dirs = dirs + "(copy)" |
| 50 | + file_path.rename(dirs) |
| 51 | + else: |
| 52 | + file_path.rename(directory_path.joinpath(file_path)) |
| 53 | + |
| 54 | + try: |
| 55 | + os.mkdir("OTHER-FILES") |
| 56 | + except: |
| 57 | + pass |
| 58 | + |
| 59 | + for dir in os.scandir(): |
| 60 | + try: |
| 61 | + if dir.is_dir(): |
| 62 | + os.rmdir(dir) |
| 63 | + else: |
| 64 | + os.rename(os.getcwd() + '/' + str(Path(dir)), os.getcwd() + '/OTHER-FILES/' + str(Path(dir))) |
| 65 | + except: |
| 66 | + pass |
| 67 | + |
| 68 | + |
| 69 | +if __name__ == "__main__": |
| 70 | + organize_junk() |
| 71 | + print("zala copy...") |
0 commit comments