[Tutor] rename files
Christopher Spears
cspears2002 at yahoo.com
Thu Jan 11 00:20:16 CET 2007
I'm trying to write a script that will rename files.
The files are in this format:
replace_dashes_stuff03
I want to rename the files to
replace.dashes.STF.v03
Here is what I have so far:
#!/usr/bin/python
import os,sys
oldFile = sys.argv[1]
if oldFile.find('_') != -1:
print "Found dashes!"
newFile_without_dashes = oldFile.replace('_','.')
print newFile_without_dashes
#os.rename(oldFile,newFile)
else:
print "No dashes!"
if newFile_without_dashes.find('stuff') != -1:
print "Found db!"
newFile_without_db =
newFile_without_dashes.replace('stuff','STF')
print newFile_without_db
#os.rename(oldFile,newFile_without_db)
Here is the result:
io at io-station-1 ./bin 125> replace_dashes.py
replace_dashes_stuff03
Found dashes!
replace.dashes.stuff03
Found db!
replace.dashes.STF03
Is there a more elegant way to do this? I haven't
figure out how to convert stuff03 to STF.v03.
THanks!
More information about the Tutor
mailing list