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

Commit ab55e64

Browse files
authored
Merge pull request #102 from gulshanbaraik01/Junk-Automation
Junk File Organizer using Python
2 parents 838016c + 550f59c commit ab55e64

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
from pathlib import Path as pt
3+
4+
DIRECTORIES = {
5+
"HTML": [".html5", ".html", ".htm", ".xhtml"],
6+
"IMAGES": [".jpeg", ".jpg", ".tiff", ".gif", ".bmp", ".png", ".bpg", "svg",
7+
".heif", ".psd"],
8+
"VIDEOS": [".avi", ".flv", ".wmv", ".mov", ".mp4", ".webm", ".vob", ".mng",
9+
".qt", ".mpg", ".mpeg", ".3gp"],
10+
"DOCUMENTS": [".oxps", ".epub", ".pages", ".docx", ".doc", ".fdf", ".ods",
11+
".odt", ".pwi", ".xsn", ".xps", ".dotx", ".docm", ".dox",
12+
".rvg", ".rtf", ".rtfd", ".wpd", ".xls", ".xlsx", ".ppt",
13+
"pptx"],
14+
"ARCHIVES": [".a", ".ar", ".cpio", ".iso", ".tar", ".gz", ".rz", ".7z",
15+
".dmg", ".rar", ".xar", ".zip"],
16+
"AUDIO": [".aac", ".aa", ".aac", ".dvf", ".m4a", ".m4b", ".m4p", ".mp3",
17+
".msv", "ogg", "oga", ".raw", ".vox", ".wav", ".wma"],
18+
"PLAINTEXT": [".txt", ".in", ".out"],
19+
"PDF": [".pdf"],
20+
"PYTHON": [".py"],
21+
"C": [".c"],
22+
"CPP": [".cpp"],
23+
"JAVA": [".java"],
24+
"XML": [".xml"],
25+
"EXE": [".exe"],
26+
"SHELL": [".sh"]
27+
28+
}
29+
30+
FILE_FORMATS = {file_format: directory
31+
for directory, file_formats in DIRECTORIES.items()
32+
for file_format in file_formats}
33+
34+
def org_junk():
35+
for entry in os.scandir():
36+
if entry.is_dir():
37+
continue
38+
file_path = pt(entry)
39+
file_format = file_path.suffix.lower()
40+
if file_format in FILE_FORMATS:
41+
directory_path = pt(FILE_FORMATS[file_format])
42+
directory_path.mkdir(exist_ok=True)
43+
file_path.rename(directory_path.joinpath(file_path))
44+
45+
for dir in os.scandir():
46+
try:
47+
os.rmdir(dir)
48+
except:
49+
pass
50+
51+
if __name__ == "__main__":
52+
org_junk()

0 commit comments

Comments
 (0)