-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocd.py
More file actions
62 lines (56 loc) · 1.99 KB
/
ocd.py
File metadata and controls
62 lines (56 loc) · 1.99 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
'''organise(path) organises all files in path into directories defined in the directories list.
Add a / (linux, unix) or double backslash(Windows) to the end of the path'''
import os
import shutil
#Defining the file types
directories = ["image", "document", "video", "audio", "musescore", "fonts",
"software", "code"]
image = ["jpg", "png", "jpeg"]
document = ["pdf", "docx", "csv"]
video = ["mp4"]
audio = ["wav", "mp3"]
musescore = ["mscz"]
fonts = ["tff", "otf","ttf"]
software = ["zip", "exe", "sh","conf"]
code = ["c", "py", "html"]
#File class. type and directory name must be equal.
class File(object):
def __init__(self, location, extension = "", type = ""):
self.location = location
self.extension = location.rpartition('.')[-1]
if self.extension in image:
self.type = "image"
elif self.extension in document:
self.type = "document"
elif self.extension in video:
self.type = "video"
elif self.extension in audio:
self.type = "audio"
elif self.extension in musescore:
self.type = "musescore"
elif self.extension in fonts:
self.type = "fonts"
elif self.extension in software:
self.type = "software"
elif self.extension in code:
self.type = "code"
else:
self.type ="null"
def organize(path):
print("WARNING:")
print("Files with same name will be replaced while moving.")
print("No changes to folders not in directories list(see code)")
print("[y/n]", end = " ")
n = input()
if n =='y':
files = os.listdir(path)
for directory in directories:
try:
os.mkdir(path + directory)
except:
pass
for f in files:
file = File(path + f)
if file.type != 'null':
shutil.move(file.location, path+file.type)
del file