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

Commit b266574

Browse files
authored
Merge pull request #15 from Mitesh2499/master
Add files via upload
2 parents c9a5f3e + c510444 commit b266574

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+
4+
os.chdir("E:\\downloads")
5+
# print(os.getcwd())
6+
7+
# check number of files in directory
8+
files = os.listdir()
9+
10+
# list of extension (You can add more if you want)
11+
extentions = {
12+
"images": [".jpg", ".png", ".jpeg", ".gif"],
13+
"videos": [".mp4", ".mkv"],
14+
"musics": [".mp3", ".wav"],
15+
"zip": [".zip", ".tgz", ".rar", ".tar"],
16+
"documents": [".pdf", ".docx", ".csv",
17+
".xlsx", ".pptx", ".doc", ".ppt", ".xls"],
18+
"setup": [".msi", ".exe"],
19+
"programs": [".py", ".c", ".cpp", ".php", ".C", ".CPP"],
20+
"design": [".xd", ".psd"],
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+
# iterate 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 Exception:
41+
print(file + " is already exist")
42+
else:
43+
try:
44+
shutil.move(file, "../download-sorting/others")
45+
except Exception:
46+
print(file + " is already exist")

0 commit comments

Comments
 (0)