forked from harrypotter0/college-projects
-
Notifications
You must be signed in to change notification settings - Fork 2
/
renameDates.py
35 lines (30 loc) · 924 Bytes
/
renameDates.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
#! python3
# renameDates.py - Renames filenames with American MM-DD-YYYY date
# to European DD-MM-YYYY.
import shutil, os, re
# Create a regex that matches files with the American date format.
datePattern = re.compile(r"""^(.*?)
((0|1)?\d)-
((0|1|2|3)?\d)-
((19|20)\d\d)
(.*?)$
""", re.VERBOSE)
k=re.compile()
# Loop over the files in the working directory.
for filenames in os.listdir('../k'):
l=datePattern.search(filenames)
print(filenames)
#TODO: Skip files without a date.
if l == None:
continue
else:
#TODO: Get the different parts of the filename.
pre = l.group(1)
month = l.group(2)
day = l.group(3)
year = l.group(4)
post = l.group(5)
#TODO: Form the European-style filename.
new=pre+day+'-'+month+'-'+year+post
#TODO: Rename the files.
shutil.move(filenames,new)