Hey there. Here is the deal.... i have a script that is supposed to
open a file based on criteria from a web form.
i cant seem to get it to work though.

here is the code:

form = cgi.FieldStorage()
DataRecord = form['DataTime'].value
Customer = form['CustName'].value # should be automatically filled in


print "Content-Type: text/html\n\n"
print

WorkingFile =
open("/var/www/stretch/web_root/SidCrops/"+Customer+"/"+DataRecord,
"r")
all_lines = WorkingFile.readlines()
WorkingFile.close()
for line in all_lines:
	print line

here is the error:
WorkingFile undefined, builtin open = <type 'file'>, Customer =
'tenderloin', DataRecord = 'Tue Jun 7 20:13:35 2005.txt'

IOError: [Errno 2] No such file or directory:
'/var/www/stretch/web_root/SidCrops/tenderloin/Tue Jun 7 20:13:35
2005.txt'
args = (2, 'No such file or directory')
errno = 2
filename = '/var/www/stretch/web_root/SidCrops/tenderloin/Tue Jun
7 20:13:35 2005.txt'
strerror = 'No such file or directory'

here is the deal.... the file is there ! i run similar code in idle and
it works.
i just dont get it. it isn't a permissions issue, its chmod 777 all
the way.
i gotta find out why this is goofing on me...

please help me!

Add the test line
print "/var/www/stretch/web_root/SidCrops/"+Customer+"/"+DataRecord
before
WorkingFile = open("/var/www ...

What comes up as full file path?

I know that spaces in a folder or filename are trouble!

Well, it printed exactly that....
printed it out like a string

/var/www/stretch/web_root/SidCrops/gritty/Sun Jun 5 18:52:55 2005.txt

it did get the two variables right.

i guess we are having a difficulty with empty spaces.

ok, i also tried from the interpereter and got the same error.
IDLE told me the file does not exist also...... and .... yes, it does.
so.... this file is based (obviously) on a timestamp. maybe i should format the way its put out. here is how i am doing it right now

from time import time, ctime
the_time = ctime(time())
try:    #Make the customer directory and create a data file by a timestamp name
	os.mkdir("/var/www/stretch/web_root/SidCrops/"+Customer) 
	OutFile = open("/var/www/stretch/web_root/SidCrops/"+Customer+"/"+the_time+".txt", "w")
	OutFile.write("")
	OutFile.close()
	print "File created successfully  "
except IOError:
   	print "IO Error"

this works to create a file that another script is able to open and write to
at a later stage in the app. Thats whats weird .

thanks

My experience with Dev-C++ and some of my Python programming tells me to avoid spaces in folder and file names with Microsoft boxes.

I would format the timestamp with time.strftime() to eliminated spaces. Give it a try, if it works you are wiser.

ok will do when i get back to the house.
thanks,
i'll let you know how it turns out.

strftime was the key.
all working now.
thanks a million.
your'e awesome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.