I never heard a response back concerning my previous question, so I decided
to write my own function. 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.
Here is the code that I am using (it runs exactly the same as the linux app
'arcgen').
<%
import os,string
filename = "whoa.mp3"
dir_path = "/u01/"
i = 0
while os.path.exists(dir_path+filename):
#filename=string.replace(filename, ".-0",".-1")
if i == 0:
filename = "%s.-%s" % (filename,i)
else:
t = i-1
filename=string.replace(filename,".-%s" % (t),".-%s" % (i))
i += 1
req.write(filename)
%>
The directory contains the following files: "whoa.mp3" and "whoa.mp3.-0".
This code will output "whoa.mp3.-1".
On 5/9/07, Sick Monkey <[EMAIL PROTECTED]> wrote:
Hey guys. I wanted to write a little desktop application that would
upload files to an external server, to a specific directory.
The desktop application is running on Mac OS X and I built a .psp script
that is running on a Red Hat server.
NOTE: This application is written for Python 2.5 (both py and psp)
My code is giving me problems, in that it is overwriting files. I was
wondering if anyone knew of a module or a method that would overcome this
dilemma. I can adapt my program to search to see if the file existed
already in the directory and append a random string sequence to keep this
from occurring, but I do not want to reinvent the wheel (if such a thing
exists) and that would clutter up my program. :)
Here is what I am currently using:
fname = os.path.basename(uploadFile.filename)
dir_path = "/u01"
open(os.path.join(dir_path, fname), 'wb').write(uploadFile.file.read())
As always, any help is greatly appreciated.
.dave
--
http://mail.python.org/mailman/listinfo/python-list