[Malvern] Another Shell Scripting Q
Andy Lowton
andy at dragonfly.demon.co.uk
Mon Dec 6 12:58:47 GMT 2004
Hi,
Assuming you do mean spaces in your first example then this does the
job. NB Both scripts work on the directory you are in.
l8z
andy
#!/usr/bin/python
import os, re
dir = "."
for file in os.listdir(dir):
m = re.search("(.+) (\d\d) (\d\d) (\d\d\d\d)$", file)
if m:
prefix = m.group(1)
year = m.group(4)
month =m.group(3)
day = m.group(2)
newfile = prefix + "_" + day + "-" + month + "-" + year
print "Renaming file: " + file + " to " + newfile
os.rename(file, newfile)
else:
print "Ignoring file: " + file
More information about the Malvern
mailing list