-
Notifications
You must be signed in to change notification settings - Fork 4
/
FileOrganizer.py
74 lines (57 loc) · 2.3 KB
/
FileOrganizer.py
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
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 6 9:35:04 2020
@author: R2J
"""
import os
import pathlib
import shutil
fileFormat = {
"Web": [".html5", ".html", ".htm", ".xhtml"],
"Picture": [".jpeg", ".jpg", ".tiff", ".gif",
".bmp", ".png", ".bpg", "svg",".heif", ".psd"],
"Video": [".avi", ".mkv",".flv", ".wmv",
".mov", ".mp4", ".webm", ".vob",
".mng",".qt", ".mpg", ".mpeg", ".3gp"],
"Document": [".oxps", ".epub", ".pages", ".docx",
".txt", ".pdf", ".doc", ".fdf",
".ods",".odt", ".pwi", ".xsn",
".xps", ".dotx", ".docm", ".dox",
".rvg", ".rtf", ".rtfd", ".wpd",
".xls", ".xlsx", ".ppt","pptx"],
"Compressed": [".a", ".ar", ".cpio", ".iso",
".tar", ".gz", ".rz", ".7z",
".dmg", ".rar", ".xar", ".zip"],
"Audio": [".aac", ".aa", ".aac", ".dvf",
".m4a", ".m4b", ".m4p", ".mp3",
".msv", "ogg", "oga", ".raw",
".vox", ".wav", ".wma"],
}
fileTypes = list(fileFormat.keys())
fileFormats = list(fileFormat.values())
for file in os.scandir():
fileName=pathlib.Path(file)
fileFormatType=fileName.suffix.lower()
src=str(fileName)
dest="Other"
if fileFormatType =="" :
print(src,'has no file extension !')
continue
else:
for formats in fileFormats:
if fileFormatType in formats:
folder=fileTypes[fileFormats.index(formats)]
if os.path.isdir(folder)== False :
os.mkdir(folder)
dest=folder
else:
if os.path.isdir("Other")== False :
os.mkdir("Other")
print(src," moved to ",dest," !")
shutil.move(src,dest)
# In FileOrganizer.exe
# FileOrganizer.py is changed to FilePrganizer.exe
# to make it work in exe file
print("FileOrganizer.py removed...")
os.remove("Other/FileOrganizer.py")
input("\n PRESS ENTER TO EXIT")