Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 910adf5

Browse files
authored
Add files via upload
1 parent 4c2fb97 commit 910adf5

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Files-Sorter
2+
This is python script that sort the files in Download directory to other directories depending on extention.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
import shutil
3+
os.chdir("E:\downloads")
4+
#print(os.getcwd())
5+
6+
#check number of files in directory
7+
files = os.listdir()
8+
9+
#list of extension (You can add more if you want)
10+
extentions = {
11+
"images": [".jpg", ".png", ".jpeg", ".gif"],
12+
"videos": [".mp4", ".mkv"],
13+
"musics": [".mp3", ".wav"],
14+
"zip": [".zip", ".tgz", ".rar", ".tar"],
15+
"documents": [".pdf", ".docx", ".csv", ".xlsx", ".pptx", ".doc", ".ppt", ".xls"],
16+
"setup": [".msi", ".exe"],
17+
"programs": [".py", ".c", ".cpp", ".php", ".C", ".CPP"],
18+
"design": [".xd", ".psd"]
19+
20+
21+
}
22+
23+
24+
#sort to specific folder depend on extenstions
25+
def sorting(file):
26+
keys = list(extentions.keys())
27+
for key in keys:
28+
for ext in extentions[key]:
29+
# print(ext)
30+
if file.endswith(ext):
31+
return key
32+
33+
34+
#iterat through each file
35+
for file in files:
36+
dist = sorting(file)
37+
if dist:
38+
try:
39+
shutil.move(file, "../download-sorting/" + dist)
40+
except:
41+
print(file + " is already exist")
42+
else:
43+
try:
44+
shutil.move(file, "../download-sorting/others")
45+
except:
46+
print(file + " is already exist")

0 commit comments

Comments
 (0)