Hello,
I am python newbie and am still discovering its wonders.
I wrote a script which renames a number of files : from Edison_03-08-2010-05-02-00_PM.7z to Edison_08-03-2010-05-02-00_PM.7z
"03-08-2010" is changed to "08-03-2010"
The script is:
import os, os.path
location = "D:/codebase/_Backups"
files = os.listdir(location)
for oldfilename in files:
parts = oldfilename.split("_")
dateparts = parts[1].split("-")
newfilename = parts[0] + "_" + dateparts[1] + "-" + dateparts[0] + "-" + dateparts[2] + "-" + parts[2] + "_" + parts[3]
print oldfilename + " : " + newfilename
os.rename(os.path.join(location, oldfilename), os.path.join(location, newfilename))
What would be a better/more elegant way of doing this ?