Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! python3
- #! DateChanger
- import re, os, shutil
- amData = re.compile(r'''^(.*?) #all the text before the actual date (1)
- ((0|1)?\d)- #the month part (2/3)
- ((0|1|2|3)?\d)- # the day part (4/5)
- ((19|20)\d\d) # four digits for the year (6/7)
- (.*?)$ # all the tekst after (8)
- ''', re.VERBOSE)
- #loop over the files in the working directory
- for amerFilename in os.listdir('.'):
- mo = amData.search(amerFilename)
- if mo == None:
- continue
- #get the different parts of the filename
- beforePart = mo.group(1)
- monthPart = mo.group(2)
- dayPart = mo.group(4)
- yearPart = mo.group(6)
- afterPart = mo.group(8)
- #Form the european style dates
- euroFilename = beforePart + dayPart + '-' + monthPart + '-' + yearPart + afterPart
- #get the full paths
- absWorkingDir = os.path.abspath('.')
- amerFilename = os.path.join(absWorkingDir, amerFilename)
- euroFilename = os.path.join(absWorkingDir, euroFilename)
- #rename the files
- print('Renaming "%s" to "%s"...' % (amerFilename, euroFilename))
- shutil.move(amerFilename, euroFilename) #uncomment after testing
Advertisement
Add Comment
Please, Sign In to add comment