PDA

View Full Version : File io HELP



GregMalick
03-12-2004, 01:22 AM
I'll go crazy if I read that file IO section ONE MORE TIME.
Please help! I'm trying to write a new file in the current scene directory.

here's the (stripped down) code:

arrSceneFile=split(Scene().filename);
fn=arrSceneFile[1] + arrSceneFile[2] + "test.txt";
info( "writing: " + fn);

fhandle=File(fn);
fhandle.open(fn,"w");
fhandle.writeln("TEST");
fhandle.close();

Info shows that fn (File Name) looks OK.
I keep getting "invalid object method open".
I'm suspecting that first parameter since they didn't describe it at all except to name it string.

If I take out the open, I get "invalid object method writeln"
at least that makes sense.

#lwrs_web
03-12-2004, 06:04 AM
fhandle=File(fn, "w");
if(!fhandle) error("File error.");
fhandle.writeln("TEST");
fhandle.close();

GregMalick
03-12-2004, 06:30 AM
My sincere thanks for responding to my question.
sometimes the simplest things are the hardest to figure out...

aloha,

NanoGator
07-21-2004, 05:05 PM
Originally posted by #lwrs_web
fhandle=File(fn, "w");
if(!fhandle) error("File error.");
fhandle.writeln("TEST");
fhandle.close();

What's causing the critical difference here?

GregMalick
07-21-2004, 09:23 PM
It's been awhile, but:

My understanding is that LScript doesn't do file handling like I'm used to. #lwrs_web took out the Open and just declared how to open the file in the File statement. I guess the file-handle allocation & open is done at the same time in LScript.

Bottom line.... #lwrs_web code works:D

faulknermano
07-22-2004, 02:55 AM
Originally posted by NanoGator
What's causing the critical difference here?


File() opens the fie and a specific mode and returns the object agent. the gregmalick's code did not specify which mode the file should be opened and used the open() method without getting a valid FileObjectAgent. opening a file only requres File().