check the existence of the local file

Subscribe to check the existence of the local file 2 posts, 2 voices

 
comp3v User

Hello all,
I will be happy if somebody can help me with following situation.
In my script, I need to check if the specified file exists on user's local disk. When I was using the extension (without Greasemonkey), it was rather with code like this:

myfile=Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
myfile.initWithPath(TryFilePath);
if (myfile.exists()) alert("You have it!");

But when I trying to do the same in greasemonkey script, it does not work! :( it seems that the very first string makes an error. I guess that it could be some security limitation... Can anybody explain how should I change my code?

Thanks in advance!

 
vOidSenses Scriptwright

you can't read and write in files with javascript from firefox, obviously for security reasons... though if you really want to do that for saving something like preferences there is a way by using this http://developer.mozilla.org/en/docs/DOM:Storage though it isn't exactly saving in a file at your choice, but it's something small you should consider to save it with GM_setValue

http://riddle.pl/-/greasemonkey/globalstorage.u... (right click>view user script source)