| 3 | |
| 4 | |
| 5 | def main(): |
| 6 | dir_path = input("Enter the directory path of the files: ") |
| 7 | |
| 8 | try: |
| 9 | print( |
| 10 | "Organising your files into [ images - music - video - executable - archive - torrent - document - code - design files]" |
| 11 | ) |
| 12 | for filename in os.listdir(dir_path): |
| 13 | absname = os.path.join(dir_path, filename) |
| 14 | # Check if files are images and you can add more extensions |
| 15 | if filename.lower().endswith( |
| 16 | (".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm") |
| 17 | ): |
| 18 | # If images folder doesn't exist then create new folder |
| 19 | if not os.path.exists("images"): |
| 20 | os.makedirs("images") |
| 21 | shutil.move(absname, "images") |
| 22 | |
| 23 | # Check if files are music and you can add more extensions |
| 24 | elif filename.lower().endswith( |
| 25 | (".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw") |
| 26 | ): |
| 27 | # If music folder doesn't exist then create new folder |
| 28 | if not os.path.exists("music"): |
| 29 | os.makedirs("music") |
| 30 | shutil.move(absname, "music") |
| 31 | |
| 32 | # Check if files are videos and you can add more extensions |
| 33 | elif filename.lower().endswith((".webm", ".mp4")): |
| 34 | # If video folder doesn't exist then create new folder |
| 35 | if not os.path.exists("video"): |
| 36 | os.makedirs("video") |
| 37 | shutil.move(absname, "video") |
| 38 | |
| 39 | # Check if files are executables |
| 40 | elif filename.lower().endswith((".exe", ".msi", ".deb", "dmg")): |
| 41 | # If executables folder doesn't exist then create new folder |
| 42 | if not os.path.exists("executables"): |
| 43 | os.makedirs("executables") |
| 44 | shutil.move(absname, "executables") |
| 45 | |
| 46 | # Check if files are archive files |
| 47 | elif filename.lower().endswith((".rar", ".tar", ".zip", ".gz")): |
| 48 | # If archive folder doesn't exist then create new folder |
| 49 | if not os.path.exists("archives"): |
| 50 | os.makedirs("archives") |
| 51 | shutil.move(absname, "archives") |
| 52 | |
| 53 | # Check if files are torrent files |
| 54 | elif filename.lower().endswith((".torrent",)): |
| 55 | # If torrent folder doesn't exist then create new folder |
| 56 | if not os.path.exists("torrent"): |
| 57 | os.makedirs("torrent") |
| 58 | shutil.move(absname, "torrent") |
| 59 | |
| 60 | # Check if files are documents |
| 61 | elif filename.lower().endswith((".txt", ".pdf", ".docx", "doc")): |
| 62 | # If documents folder doesn't exist then create new folder |