-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting.py
More file actions
158 lines (96 loc) · 3.99 KB
/
sorting.py
File metadata and controls
158 lines (96 loc) · 3.99 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import sys
import os
import shutil
def deletefile(path):
files = os.listdir(path)
for file in files:
if os.path.isfile(os.path.join(path,file)):
os.remove(os.path.join(path,file))
def createfolder(path):
path2 = path
fol = "videos"
path = os.path.join(path,fol)
if not os.path.isdir(path):
os.mkdir(path)
path = path2
fol = "audios"
path = os.path.join(path,fol)
if not os.path.isdir(path):
os.mkdir(path)
path = path2
fol = "pictures"
path = os.path.join(path,fol)
if not os.path.isdir(path):
os.mkdir(path)
path = path2
fol = "other"
path = os.path.join(path,fol)
if not os.path.isdir(path):
os.mkdir(path)
path = path2
fol = "text"
path = os.path.join(path,fol)
if not os.path.isdir(path):
os.mkdir(path)
path = path2
fol = "mp4"
path = os.path.join(path,fol)
if not os.path.isdir(path):
os.mkdir(path)
path = path2
def filesort(path):
try:
fname = ""
for k,j,i in os.walk(path):
for file in i:
if file.endswith(".txt"):
fromthis = os.path.join(path, file)
tothis = os.path.join(path, "text")
shutil.move(fromthis,tothis)
elif file.endswith(".avi") or file.endswith(".mov"):
fromthis = os.path.join(path, file)
tothis = os.path.join(path, "videos")
shutil.copy(fromthis,tothis)
elif file.endswith(".jpg") or file.endswith(".jpeg"):
fromthis = os.path.join(path,file)
tothis = os.path.join(path,"pictures")
shutil.copy(fromthis,tothis)
elif file.endswith(".mp3") or file.endswith(".m4a"):
fromthis = os.path.join(path,file)
tothis = os.path.join(path,"audios")
shutil.copy(fromthis,tothis)
elif file.endswith(".mp4"):
fromthis = os.path.join(path,file)
tothis = os.path.join(path,"mp4")
shutil.copy(fromthis,tothis)
else:
fromthis = os.path.join(path,file)
tothis = os.path.join(path,"other")
shutil.copy(fromthis,tothis)
except Exception as E:
print("This File Already Exists -> ",file )
def main():
print("-------------------------------------------------------------------------------------------------------")
print("Welcome To Automated Sorting Script By Piyush Rohokale...")
if len(sys.argv) != 2:
print("Please Enter the Path as CommandLine Argument To the Script....")
print("-------------------------------------------------------------------------------------------------------")
exit()
if not os.path.isabs(sys.argv[1]):
sys.argv[1] = os.path.abspath(sys.argv[1])
print("Your Entered Path is : ",sys.argv[1])
print("Creating Folders...")
path = sys.argv[1]
createfolder(path)
print("Folders Are Created...")
print("Sorting The Files To There Designeted Folders...")
filesort(path)
deletefile(path)
print("Files Have been sorted...")
print("-------------------------------------------------------------------------------------------------------")
print(" Leetcode -> https://leetcode.com/u/piyushrohokale2525/")
print(" Github -> https://github.com/VyankateshRohokale")
print(" Email Address -> piyushrohokale2525@gmail.com")
print("-------------------------------------------------------------------------------------------------------")
if __name__ == "__main__":
main()