(Jan-28-2017, 05:25 PM)pyth0nus3r Wrote: So below is the program that I am using to change files with European (DD-MM-YYYY) style date to American (MM-DD-YYYY) Style Date:
Quote:#! python3
# renameDates.py - Renames filenames with American MM-DD-YYYY date format
# to European DD-MM-YYYY.
Not very clear... changing European to American or vice-versa? Your regexp implies that your input is American (month first).
Several remarks:
(0|1|2|3)
is best replaced by[0123]
or even[0-3]
- you can use
re.sub
(and back-references) to replace just the part that matches so you regexp doesn't have to deal with the bits outside the date part:
datePattern = re.compile(r'([01]?\d)-([0-3]?\d)-((19|20)\d\d)') nameOut=re.sub(datePattern,r'\2-\1-\3',nameIn)If
nameOut==nameIn
, the regexp was unmatched... or you where dealing with a file dated Jan 1st, Feb 2nd, etc... In any case you don't need to rename the file.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Your one-stop place for all your GIMP needs: gimp-forum.net