-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesSeperator.py
43 lines (40 loc) · 1.43 KB
/
filesSeperator.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
import os
try:
from pathlib import Path
except:
os.system('python -m pip install pathlib')
from pathlib import Path
"""
Download or copy and Paste this cose and save with .py extension and
run inside the folder that you want to segregate
"""
subcategory={
'DOCUMENTS':['.pdf','.txt','.doc','rtf','.pptx','.docx',
'.odt'],
'AUDIO':['.mp3','.m4b','.m4a','.webvtt','.cea-608/708',
'.dfxp', '.sami', '.scc', '.srt', '.ttml', '.3gpp'],
'VIDEOS':['.mov','.avi','.mp4','.3gp','.ogg', '.oga', '.ogv',
'.ogx','.wmv','.webm','.flv','.avi','.QuickTime',
'.hdv','.mxf','.mpeg-2','.ts','.wav','.lfx',
'.gfx''.vob'],
'IMAGES':['.jpg','.jpeg','.raw','.png','.tiff','.gif',],
'PROGRAMMING FILES':['.htm','.html','.cpp','.c','.py','.css','.java']
}
def findTheCategory (value):
for filename,ext in subcategory.items():
for extension in ext:
if extension == value:
return filename
return 'MISC'
def organizeDir():
for i in os.scandir():
if i.is_dir():
continue
filePath=Path(i)
fileType=filePath.suffix.lower()
directory = findTheCategory(fileType)
directoryPath=Path(directory)
if directoryPath.is_dir() !=True:
directoryPath.mkdir()
filePath.rename(directoryPath.joinpath(filePath))
organizeDir()