-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile_organizer.py
More file actions
82 lines (70 loc) · 2.49 KB
/
file_organizer.py
File metadata and controls
82 lines (70 loc) · 2.49 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
71
72
73
74
75
76
77
78
79
80
81
82
import argparse
import sys
import os
zips = []
folders = []
executables = []
documents = []
videos = []
pictures = []
songs = []
misc = []
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--f', type=str, help="Directory to be organized.")
args = parser.parse_args()
sys.stdout.write(str(orga(args)))
def orga(args):
fileName = args.f
files_list = os.listdir(fileName)
for i in files_list:
if i[-3:] in ["zip","rar"]:
zips.append(i)
elif i[-3:] in ["mp3","wav","ogg"]:
songs.append(i)
elif i[-3:] in ["mp4","mkv","mov","vlc"]:
videos.append(i)
elif i[-4:] in ["pptx","docx","xlsx"] or i[-3:] in ["pdf","txt","doc","PDF"]:
documents.append(i)
elif i[-3:]=="exe":
executables.append(i)
elif i[-3:] in ["jpg","bmp","gif","png"] or i[-4:]=="jpeg":
pictures.append(i)
elif i[-3:] in ["ini","iso","srt"] or i[-7:]=="torrent" or i[-4:] in ["html","webp"]:
misc.append(i)
else:
folders.append(i)
if not os.path.exists(fileName + "folders\\"):
os.makedirs(fileName + "folders\\")
for i in folders:
os.rename(fileName + i, fileName + "folders\\" + i)
if not os.path.exists(fileName + "zips\\"):
os.makedirs(fileName + "zips\\")
for i in zips:
os.rename(fileName + i, fileName + "zips\\" + i)
if not os.path.exists(fileName + "executables\\"):
os.makedirs(fileName + "executables\\")
for i in executables:
os.rename(fileName + i, fileName + "executables\\" + i)
if not os.path.exists(fileName + "videos\\"):
os.makedirs(fileName + "videos\\")
for i in videos:
os.rename(fileName + i, fileName + "videos\\" + i)
if not os.path.exists(fileName + "documents\\"):
os.makedirs(fileName + "documents\\")
for i in documents:
os.rename(fileName + i, fileName + "documents\\" + i)
if not os.path.exists(fileName + "pictures\\"):
os.makedirs(fileName + "pictures\\")
for i in pictures:
os.rename(fileName + i, fileName + "pictures\\" + i)
if not os.path.exists(fileName + "songs\\"):
os.makedirs(fileName + "songs\\")
for i in songs:
os.rename(fileName + i, fileName + "songs\\" + i)
if not os.path.exists(fileName + "misc\\"):
os.makedirs(fileName + "misc\\")
for i in misc:
os.rename(fileName + i, fileName + "misc\\" + i)
if __name__ == '__main__':
main()