-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathmain.py
28 lines (23 loc) · 979 Bytes
/
main.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
import os
import platform
ROOT_DIR = os.getcwd() + '/root'
PATH_DELIMITER = ''
DESTINATION_FILE_DELIMITER = '-'
COUNTER = 0
if (platform.system() == 'Linux') or (platform.system() == 'Darwin'):
PATH_DELIMITER = '/'
elif (platform.system() == 'Windows'):
PATH_DELIMITER = '\\'
for current_dir in os.listdir(ROOT_DIR):
subdir = ROOT_DIR + PATH_DELIMITER + current_dir
if os.path.isdir(subdir):
print('Now working with: "' + subdir + '" directory')
COUNTER = 0
for current_file in os.listdir(subdir):
COUNTER += 1
current_file_full_path = subdir + PATH_DELIMITER + current_file
renamed_file_full_path = subdir + PATH_DELIMITER + current_dir + DESTINATION_FILE_DELIMITER + str(COUNTER) + '.' + current_file.split('.')[-1]
try:
os.rename(current_file_full_path, renamed_file_full_path)
except Exception as e:
print('Error occurred because: ' + e)