On Sat, Jul 07, 2007 at 10:45:30PM +0100, Rolando Pereira wrote: > Ian Mallett escreveu: > >Hi, > >Suppose you have an image file. Call it "blah.png". If I want to copy it > >to another directory and rename it "Ogg.png", how would I do that with > >python code? > > > > Well, this is more of a [Tutor]'s question than a Pygame's question, but > at least this one I can anwser. > > (This was done in 5 minutes or so, so it might have a but or something :D ) > > f = file("full_path_to_blah.png") > n = file("full_path_to_Ogg.png", "w") # We add "w", so that if > the file so that if the file > doesn't exist, it > will be created > > n.write(f.read()) > n.close() > > Presto, there should be now two similar images :D
Hi, I tend to use the shutil module for this kind of work. See shutil.copy() and shutil.copy2(). To manipulate file path/names I tend to use the os.path functions. See os.path.join(), os.path.split(), os.path.splitext(). cheers, John.