-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveRenameFile.py
More file actions
39 lines (23 loc) · 922 Bytes
/
MoveRenameFile.py
File metadata and controls
39 lines (23 loc) · 922 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
33
34
35
36
37
38
39
import os
import datetime
#List what is in drive
x = os.listdir('J:\Hold')
y = 'J:\Hold\\'
#Change working drive
os.chdir('J:\Hold')
#For loop to change file name to have the name and modification time in same name.
for file in x:
print(file)
#Path to file and file name
file2 = y + file
#Modification time
modTimesinceEpoc = os.path.getmtime(file2)
modificationTime = datetime.datetime.fromtimestamp(modTimesinceEpoc)
modificationTime = str(modificationTime)
modificationTime = modificationTime.replace("-", "")
modificationTime = modificationTime.replace(":", "")
modificationTime = modificationTime.replace(" ","")
#Take off the extension
newfile = file.replace(".txt", "")
#Adding the modification time to the name of file and putting extension back on.
os.rename(file, newfile + modificationTime + '.txt')