-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenameFiles.py
More file actions
32 lines (23 loc) · 928 Bytes
/
Copy pathRenameFiles.py
File metadata and controls
32 lines (23 loc) · 928 Bytes
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
import os
import datetime
# Set the path where to rename the files from
path = "D:\\Pictures\\Phone\\Sort\\Rename"
# Loop through list of files
for file_name in os.listdir(path):
# If the four characters of a file name are digits assume it's been renamed already and skip it
if (file_name[:4].isdigit() and len(file_name) >= 4):
print("Skipped " + file_name)
continue
# Full file path
full_path = path + "\\" + file_name
# Get file's created date in iso format
created_date = datetime.datetime.fromtimestamp(os.path.getctime(full_path)).strftime("%Y-%m-%d")
# New file name
new_file_name = created_date + "_" + file_name;
# New file name full file path
renamed_file = path + "\\" + new_file_name;
# Rename the file
os.rename(full_path, renamed_file)
# Print file that was renamed
print("Renamed " + file_name + " to " + new_file_name)
#test commit