|
4 | 4 | dir_path = os.path.dirname(os.path.realpath(__file__))
|
5 | 5 |
|
6 | 6 | try:
|
7 |
| - print("Organising your files...") |
| 7 | + print("Organising your files intro [ images - music - video -executable - archive - torrent - document - code ]") |
8 | 8 | for filename in os.listdir(dir_path):
|
9 |
| - # Check if files are images |
| 9 | + # Check if files are images and you can add more extentions |
10 | 10 | if filename.lower().endswith((".png", ".jpg", ".jpeg", ".gif", ".bmp", ".pbm", ".pnm")):
|
11 |
| - # If images folder doesnt exist then create |
| 11 | + # If images folder doesnt exist then create new folder |
12 | 12 | if not os.path.exists("images"):
|
13 | 13 | os.makedirs("images")
|
14 | 14 | shutil.copy2(filename, "images")
|
15 | 15 | os.remove(filename)
|
16 | 16 |
|
17 |
| - # Check if files are music |
| 17 | + # Check if files are music and you can add more extentions |
18 | 18 | if filename.lower().endswith((".wav", ".mp3", ".flac", ".3gp", ".aa", ".aax", ".aiff", ".raw")):
|
19 | 19 | # If music folder doesnt exist then create
|
20 | 20 | if not os.path.exists("music"):
|
21 | 21 | os.makedirs("music")
|
22 | 22 | shutil.copy2(filename, "music")
|
23 | 23 | os.remove(filename)
|
24 | 24 |
|
| 25 | + # Check if files are videos and you can add more extentions |
| 26 | + if filename.lower().endswith((".webm", ".mp4")): |
| 27 | + # If music folder doesnt exist then create |
| 28 | + if not os.path.exists("music"): |
| 29 | + os.makedirs("music") |
| 30 | + shutil.copy2(filename, "music") |
| 31 | + os.remove(filename) |
| 32 | + |
25 | 33 | # Check if files are executables
|
26 |
| - if filename.lower().endswith((".exe", ".tar", ".deb")): |
| 34 | + if filename.lower().endswith((".exe", ".msi", ".deb")): |
27 | 35 | # If executables folder doesnt exist then create
|
28 | 36 | if not os.path.exists("executables"):
|
29 | 37 | os.makedirs("executables")
|
30 | 38 | shutil.copy2(filename, "executables")
|
31 | 39 | os.remove(filename)
|
32 | 40 |
|
| 41 | + # Check if files are archive files |
| 42 | + if filename.lower().endswith((".rar", ".tar" , ".zip" , ".gz")): |
| 43 | + # If executables folder doesnt exist then create |
| 44 | + if not os.path.exists("archives"): |
| 45 | + os.makedirs("archives") |
| 46 | + shutil.copy2(filename, "archives") |
| 47 | + os.remove(filename) |
| 48 | + |
| 49 | + |
| 50 | + # Check if files are torrent files |
| 51 | + if filename.lower().endswith((".torrent",)): |
| 52 | + # If executables folder doesnt exist then create |
| 53 | + if not os.path.exists("torrent"): |
| 54 | + os.makedirs("torrent") |
| 55 | + shutil.copy2(filename, "torrent") |
| 56 | + os.remove(filename) |
| 57 | + |
33 | 58 | # Check if files are documents
|
34 |
| - if filename.lower().endswith((".txt", ".pdf", ".docx")): |
| 59 | + if filename.lower().endswith((".txt", ".pdf", ".docx" , "doc")): |
35 | 60 | # If executables folder doesnt exist then create
|
36 | 61 | if not os.path.exists("documents"):
|
37 | 62 | os.makedirs("documents")
|
38 | 63 | shutil.copy2(filename, "documents")
|
39 | 64 | os.remove(filename)
|
40 | 65 |
|
| 66 | + |
| 67 | + # Check if files are code files |
| 68 | + if filename.lower().endswith((".py", ".php", ".html" , ".css" , ".js")): |
| 69 | + # If executables folder doesnt exist then create |
| 70 | + if not os.path.exists("code"): |
| 71 | + os.makedirs("code") |
| 72 | + shutil.copy2(filename, "code") |
| 73 | + os.remove(filename) |
| 74 | + |
| 75 | + |
41 | 76 | except OSError:
|
42 |
| - print("Error") |
| 77 | + print("Error happened ...... try again") |
43 | 78 | finally:
|
44 | 79 | # When script is finished clear screen and display message
|
45 | 80 | os.system("cls" if os.name == "nt" else "clear")
|
|
0 commit comments