[Tutor] Changing files names
Bryan
juicebypi216 at yahoo.com
Tue Sep 14 22:01:09 CEST 2004
Hi everyone,
Basically, what I'm trying to do is change all of the file names under one directory. There are probably about 500 different files, but they all have similar names, just numbered from lets say 5000 to 5500.
So far, I've written a program that looks somewhat like this, trying to convert the first three files in the folder:
>>import glob, os
>>from sets import Set
>>skip = Set(['1.2.20.5000.raw',
'1.2.27.5001.raw',
'1.2.31.5002.raw',
])
>>basedir = r'F:\Python\Renaming\Data'
>>for fname in glob.glob(basedir + '*.raw'):
if fname in skip: continue
newname = basedir + 'bryfile.' + fname[-8:]
print 'renaming', fname, newname
os.rename(fname, newname)
So basically, I'm trying to change the file name so it looks like bryfile.5000.raw, bryfile..5001.raw, bryfile.5002.raw, and so on.
This program does not work, and does not print out, and I'm not sure why.
Also, do I really have to enter in all of the original file names? Is there a way to tell Python to read all files in the folder, or all files with a 1.2.20.* extension? As you can see, the problem with this method is that the last 4 numbers of the file tell where the file lies in the list (for example, 5000), But the middle section of the file name (the 20) does not go in numeric order.
Thanks for the help
Bryan
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040914/db32b772/attachment.htm
More information about the Tutor
mailing list