-
Notifications
You must be signed in to change notification settings - Fork 0
/
organize_pictures.py
31 lines (24 loc) · 1008 Bytes
/
organize_pictures.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
from os import listdir
from os import mkdir
from os import path
from os import rename
basePath = '' #Insert path for organize here
lastFolderName = ''
for file in listdir(basePath):
if('.jpg' in file or '.jpeg' in file or '.JPEG' in file or '.JPG' in file):
if('(' in file):
indexForSubstring = file.index('(')
folderName = file[:indexForSubstring]
else:
indexForSubstring = file.index('.')
folderName = file[:indexForSubstring]
folderName = folderName.strip()
newFolderPath = basePath + '\\' + folderName
print('-> File "{}" will be moved to folder "{}".'.format(file, newFolderPath))
if not (path.exists(newFolderPath)):
mkdir(newFolderPath)
print('---> Folder {} doesnt exists and was created!'.format(newFolderPath))
oldPath = basePath + '\\' + file
newPath = newFolderPath + '\\' + file
rename(oldPath, newPath)
lastFolderName = folderName