larsmrx

AmDateToEuroDate

Oct 7th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. #! python3
  2. #! DateChanger
  3.  
  4. import re, os, shutil
  5.  
  6. amData = re.compile(r'''^(.*?) #all the text before the actual date (1)
  7.                        ((0|1)?\d)- #the month part (2/3)
  8.                        ((0|1|2|3)?\d)- # the day part (4/5)
  9.                        ((19|20)\d\d) # four digits for the year (6/7)
  10.                        (.*?)$ # all the tekst after (8)
  11.                    ''', re.VERBOSE)
  12.  
  13.  
  14. #loop over the files in the working directory
  15. for amerFilename in os.listdir('.'):
  16.     mo = amData.search(amerFilename)
  17.     if mo == None:
  18.         continue
  19.  
  20.  
  21. #get the different parts of the filename
  22.  
  23.     beforePart = mo.group(1)
  24.     monthPart = mo.group(2)
  25.     dayPart = mo.group(4)
  26.     yearPart = mo.group(6)
  27.     afterPart = mo.group(8)
  28.  
  29.  
  30. #Form the  european style dates
  31.  
  32.     euroFilename = beforePart + dayPart + '-' + monthPart + '-' + yearPart + afterPart
  33.  
  34. #get the full paths
  35.  
  36.     absWorkingDir = os.path.abspath('.')
  37.     amerFilename = os.path.join(absWorkingDir, amerFilename)
  38.     euroFilename = os.path.join(absWorkingDir, euroFilename)
  39.  
  40. #rename the files
  41.  
  42.     print('Renaming "%s" to "%s"...' % (amerFilename, euroFilename))
  43.     shutil.move(amerFilename, euroFilename) #uncomment after testing
Advertisement
Add Comment
Please, Sign In to add comment