[javascript-dev] String declaration and opening Files
Sasha Harris-Cronin
sasha at mortalspaces.com
Fri Apr 11 13:17:53 MDT 2008
- Previous message: [javascript-dev] Re: Dumping an image from jit.sketch to a matrix?
- Next message: [javascript-dev] Re: String declaration and opening Files
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I ran into an interesting mac javascript feature yesterday. I found the workaround, but thought I'd mention it. Basically, initializing a String at declaration will interfere with testing for a file with the same name as that string.
Or, more verbosely, the following function will always report that the file with the filename passed to it exists, even if the file does not.
function checkForFile(fileName) //check to see if file exists
{
var s = new String(fileName);
f = new File(s, "read");
if (f.isopen) //if succeed in opening file
{
f.close();
post("found file: " + fileName + "
");
return (true);
}
else //file doesn't exist
{
f.close(); //anal retentively close file
post("could not find file: " + fileName + "
");
return (false);
}
}
If I change the string declaration to be like this, however:
var s = new String();
s = filename;
Then it works fine. Don't pick on programming style, by the way. I know that it is fully unnecessary to declare s in the first place. This was just a concise example. It is not specific to a local function either. If a string is declared with that text outside of the function, the function still misreports the file.
String is obviously part of javascript 1.5, but File IO is a max/msp add. I'm curious about what's going on under the hood to make that happen.
sasha
--
--- sasha harris-cronin ----
-- sasha at mortalspaces.com --
--- www.mortalspaces.com ---
- Previous message: [javascript-dev] Re: Dumping an image from jit.sketch to a matrix?
- Next message: [javascript-dev] Re: String declaration and opening Files
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
