-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (44 loc) · 1.64 KB
/
main.py
File metadata and controls
70 lines (44 loc) · 1.64 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
'''
Author --> Kush Namdev ;
Gmail --> kushnamdev23@gmail.com ;
It is a script which can clear your clutter in seconds ,
you can add more functions to it .
It is free to use and modify according to your preferences ..
you can add more file types .
'''
import os
def createIfNotExists(folder):
if not os.path.exists(folder):
os.makedirs(folder)
def move(foldername, files):
for file in files:
os.replace(file,f"{foldername}/{file}")
files = os.listdir()
files.remove("main.py")
print(files)
createIfNotExists('Images')
createIfNotExists('Docs')
createIfNotExists('Media')
createIfNotExists('Others')
createIfNotExists('Zipfies')
imgExts = [".png", ".jpeg", ".jpg"]
images = [file for file in files if os.path.splitext(file)[1].lower() in imgExts ]
print(images)
docExts = [".txt", ".doc", ".docx", ".odt", ".pdf"]
docs = [ file for file in files if os.path.splitext(file)[1].lower() in docExts]
print(docs)
mediaExts = [".3gp", ".mp3", ".flv", ".mp4"]
medias = [ file for file in files if os.path.splitext(file)[1].lower() in mediaExts]
zipExts = [".zip", ".rar", ".7z", ".zipx", ".tar.gz", ".pkg", ".rpm"]
zipfiles = [file for file in files if os.path.splitext(file)[1].lower() in zipExts]
others = []
for file in files:
ext = os.path.splitext(file)[1].lower()
if (ext not in mediaExts) and (ext not in docExts) and (ext not in imgExts) and (ext not in zipExts ) and os.path.isfile(file):
others.append(file)
print(others)
move('Images', images)
move('Docs', docs)
move('Media', medias)
move('Others', others)
move('Zipfiles', zipfiles)