1
1
import os
2
2
import shutil
3
- < << << << HEAD
4
-
5
- os .chdir ("E:\\ downloads" )
6
- # print(os.getcwd())
7
-
8
- # check number of files in directory
9
- files = os .listdir ()
10
-
11
- # list of extension (You can add more if you want)
12
- == == == =
13
3
os .chdir ("E:\downloads" )
14
4
#print(os.getcwd())
15
5
16
6
#check number of files in directory
17
7
files = os .listdir ()
18
8
19
9
#list of extension (You can add more if you want)
20
- > >> >> >> 760 b764f0e43d93842442ba57e745ef195a27d42
21
10
extentions = {
22
11
"images" : [".jpg" , ".png" , ".jpeg" , ".gif" ],
23
12
"videos" : [".mp4" , ".mkv" ],
24
13
"musics" : [".mp3" , ".wav" ],
25
14
"zip" : [".zip" , ".tgz" , ".rar" , ".tar" ],
26
- << << << < HEAD
27
- "documents" : [".pdf" , ".docx" , ".csv" ,
28
- ".xlsx" , ".pptx" , ".doc" , ".ppt" , ".xls" ],
29
- "setup" : [".msi" , ".exe" ],
30
- "programs" : [".py" , ".c" , ".cpp" , ".php" , ".C" , ".CPP" ],
31
- "design" : [".xd" , ".psd" ],
32
- }
33
-
34
-
35
- # sort to specific folder depend on extenstions
36
- == == == =
37
15
"documents" : [".pdf" , ".docx" , ".csv" , ".xlsx" , ".pptx" , ".doc" , ".ppt" , ".xls" ],
38
16
"setup" : [".msi" , ".exe" ],
39
17
"programs" : [".py" , ".c" , ".cpp" , ".php" , ".C" , ".CPP" ],
44
22
45
23
46
24
#sort to specific folder depend on extenstions
47
- >> >> >> > 760 b764f0e43d93842442ba57e745ef195a27d42
48
25
def sorting (file ):
49
26
keys = list (extentions .keys ())
50
27
for key in keys :
@@ -54,28 +31,17 @@ def sorting(file):
54
31
return key
55
32
56
33
57
- < << << << HEAD
58
- # iterate through each file
59
- == == == =
60
34
#iterat through each file
61
- >> >> >> > 760 b764f0e43d93842442ba57e745ef195a27d42
62
35
for file in files :
63
36
dist = sorting (file )
64
37
if dist :
65
38
try :
66
39
shutil .move (file , "../download-sorting/" + dist )
67
- < << << << HEAD
68
- except Exception :
69
- == == == =
70
40
except :
71
- >> >> >> > 760 b764f0e43d93842442ba57e745ef195a27d42
72
41
print (file + " is already exist" )
73
42
else :
74
43
try :
75
44
shutil .move (file , "../download-sorting/others" )
76
- < << << << HEAD
77
- except Exception :
78
- == == == =
79
45
except :
80
- >> >> >> > 760 b764f0e43d93842442ba57e745ef195a27d42
81
46
print (file + " is already exist" )
47
+
0 commit comments