admin管理员组文章数量:1279090
I am using an app that uses only JavaScript as its scripting language. I have a .ini
file and I need to see if it exists. Is this possible?
Also, if it doesn't exist, how can I halt the execution?
I am using an app that uses only JavaScript as its scripting language. I have a .ini
file and I need to see if it exists. Is this possible?
Also, if it doesn't exist, how can I halt the execution?
Share Improve this question edited Jul 18, 2018 at 19:52 Marco Altieri 3,8182 gold badges37 silver badges50 bronze badges asked Sep 7, 2011 at 17:38 Joan VengeJoan Venge 331k223 gold badges495 silver badges706 bronze badges 4- what app are you using? it depends on what they provide for you. – Daniel A. White Commented Sep 7, 2011 at 17:41
- As long as Javascript is not running in the server, then it might be possible to do that. But I need to know the OS that you are targeting.? – billygoat Commented Sep 7, 2011 at 17:42
- Sorry it's Win7. Also the app I use doesn't give any extra functionality other than controlling the app, which are stuff like adding effects, text on an image, resize image, delete layers, etc. But no generic file IO or libs. – Joan Venge Commented Sep 7, 2011 at 17:45
- it would be helpful to know what it is. – Daniel A. White Commented Sep 7, 2011 at 18:12
3 Answers
Reset to default 3Ok doing something like this works:
var file = new File(datafile);
var result = file.open ('r');
if result
is true
, then the file exists, otherwise false
means the file does not exist.
"Yes", assuming ActiveX can be used.
See FileSystemObject aka "FSO" (the FileExists method in particular). FSO is part of Windows Scripting.
It is also possible to use the MSXML load method to access a "file://" and catch the appropriate error. (I don't know if a vanilla XmlHttpRequest request of "file://" can be used here, and/or in what contexts... it might differ between the XHR from MSXML and the one baked into IE7/8 as well.)
Happy coding.
If the JavaScript runs from an HTA/HTML Aplication or Windows Sidgebar Gadget, etc, then it's in "Security Level 0" or "Demigod Mode".
On the other hand, an HTA runs as a fully trusted application and therefore has more privileges than a normal HTML file...
Try this:
var myfile = new File(myfile_path);
if (!myfile.exists) {
alert(myfile + " could not be found!");
}
版权声明:本文标题:Is it possible to check if a file exists on disk using Javascript (not running in a browser)? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741281285a2370022.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论