file uploader
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun May 13 19:41:26 EDT 2007
En Sun, 13 May 2007 18:41:16 -0300, Sick Monkey <sickcodemonkey at gmail.com>
escribió:
> If anyone has a simpler way of checking to see if
> a file already exists (prior to uploading to a server) and renaming it,
> please let me know.
I will ignore the "server" part...
> Here is the code that I am using (it runs exactly the same as the linux
> app
> 'arcgen').
> [...]
> t = i-1
> filename=string.replace(filename,".-%s" % (t),".-%s" % (i))
If the original filename contained .-1 somewhere, you're modifying it.
This is safer and shorter:
import os,string
filename = "whoa.mp3"
dir_path = "/u01/"
ofilename = filename
i = 0
while os.path.exists(dir_path+filename):
filename = "%s.-%s" % (ofilename,i)
i += 1
req.write(filename)
--
Gabriel Genellina
More information about the Python-list
mailing list