file Object

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
philspitler
Posts: 39
Joined: November 2nd, 2005, 10:20 am
Contact:

Hi,
I have been using a dialog box to open a file and read from it.

var f=File.openDialog("select a file");
var ok=f.open("r");

This works great but now I want to have the filename in a variable instead of using a dialog box.

I thought it would be something like this below,

var f=File.open("test.txt");
var ok=f.open("r");

But it's not right.

Looking through docs, I cannot seem to find the correct syntax.

Thanks.

Phil
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

You have to specify the whole path:

var myFilePath = "C:/Temp";
var myFileName = "test.txt";

var myFile = new File(myFilePath + "/" + myFileName);
var fileOK = myFile.open("r");


Dan
philspitler
Posts: 39
Joined: November 2nd, 2005, 10:20 am
Contact:

Yep, I just put the test.txt in there as an example.

It was the "new" that I was missing.

Thanks once again Dan.

Phil
Phil Spitler
User avatar
lloydalvarez
Enhancement master
Posts: 460
Joined: June 17th, 2004, 9:27 am
Location: New York City, NY
Contact:

btw, the difference between adding the new and not is that if you have new File and the file does not exist then it will create a new file object if you don't add the new and the file doesn't exist you will get an error.

-Lloyd
Post Reply