forked from metafy-social/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
123 lines (107 loc) · 4.84 KB
/
Copy pathmain.py
File metadata and controls
123 lines (107 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
import shutil
from sys import platform
from threading import Thread
organise_folder = download_path = None
category = {"Audios": [".aif", ".cda", ".mid.mp3", ".mpa", ".ogg", ".wav", ".wma", ".wpl", ".midi"],
"Compressed": [".7z", ".arj", ".deb", ".pkg", ".rar", ".rpm", ".tar", ".z", ".zip", ".gz"],
"Documents": [".bin", ".dmg", ".iso", ".toast", ".vcd", ".csv", ".dat", ".db", ".log", ".mdb", ".sav",
".sql", ".tar", ".xml", ".dbf", ".email", ".eml", ".emlx", ".msg", ".oft", ".ost", ".pst",
".vcf", ".asp", ".cer", ".cfm", ".cgi", ".css", ".htm", ".js", ".jsp", ".part", ".php", ".py",
".rss", ".xhtml", ".fnt", ".fon", ".otf", ".ttf", ".doc", ".odt", ".pdf", ".rtf", ".tex",
".txt", ".wpd", ".key", ".odp", ".pps", ".ppt", ".pptx", ".c", ".cgi", ".class", ".cpp",
".cs", ".h", ".java", ".php", ".py", ".sh", ".swift", ".vb", ".ods", ".xls", ".xlsm", ".xlsx",
".docx", ".aspx", ".html"],
"Images": [".ai", ".bmp", ".gif", ".ico", ".jpeg", ".png", ".ps", ".psd", ".svg", ".tif", ".jpg", ".tiff"],
"Videos": [".3g2", ".3gp", ".avi", ".flv", ".h264", ".m4v", ".mkv", ".mov", ".mp4", ".mpg.rm", ".swf",
".vob", ".wmv", ".mpeg", ".webm"],
"Setups": [".apk", ".bat", ".bin", ".cgi", ".com", ".exe", ".gadget", ".jar", ".msi", ".py", ".wsf"],
"Systemfiles": [".bak", ".cab", ".cfg", ".cpl", ".cur", ".dll", ".dmp", ".drv", ".icns", ".ico", ".ini",
".lnk", ".msi",
".sys", ".tmp"]}
def movers(source, destination):
if not os.path.exists(destination):
os.makedirs(destination)
try:
shutil.move(source, destination)
except OSError as error:
print(str(source) + " <= File is open. Error => ", error)
def our_cat_dir(main_path, filepath):
for cat in category:
if filepath == os.path.join(main_path, cat):
return True
return False
def our_ext_dir(main_path, filepath):
for cat in category:
for ext in category[cat]:
if filepath == os.path.join(main_path, ext):
return True
return False
def org_by_cat(path):
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isdir(file_path):
if not our_cat_dir(path, file_path):
Thread(target=org_by_cat, args=[file_path]).start()
continue
else:
file_name, file_extension = os.path.splitext(file_path)
for cat in category:
cat_folder = os.path.join(path, cat)
if file_extension.lower() in category[cat]:
movers(file_path, cat_folder)
def org_by_ext(path):
for file in os.listdir(path):
if os.path.isdir(file):
if not our_ext_dir(path, file):
Thread(target=org_by_ext, args=[file]).start()
continue
else:
file_path = os.path.join(path, file)
file_name, file_extension = os.path.splitext(file_path)
for cat in category:
if file_extension.lower() in category[cat]:
ext_folder = os.path.join(path, file_extension)
movers(file_path, ext_folder)
def main():
global organise_folder, download_path
if platform == "linux" or platform == "linux2":
download_path = "/home/" + os.environ.get('USERNAME') + "/Downloads"
elif platform == "win32":
download_path = "C:\\Users\\" + os.environ.get('USERNAME') + "\\Downloads"
while True:
print("Press Q to exit anytime.")
path = input('''\tOrganise Custom Directory? Enter Path (default : Downloads)\n>>>''')
if path == "q":
break
elif path == "":
organise_folder = download_path
else:
organise_folder = path
if not os.path.exists(organise_folder):
print("\nInvalid Path.")
continue
else:
if os.path.isdir(organise_folder):
break
else:
print("\nEntered Path not a directory.")
continue
while True:
organise_type = input("\nIn what way do you want to organize.\n\t"
+ "1) Organize files by category.\n\t"
+ "2) Organize files by extension.\n>>>")
if organise_type == "q":
break
elif organise_type == "1":
print("Working")
org_by_cat(organise_folder)
print("Done")
break
elif organise_type == "2":
print("Working")
org_by_ext(organise_folder)
print("Done")
break
if __name__ == "__main__":
main()