[英]How to check file existance in windows %temp% folder using XUL/Javascript?
Here I am trying to check that if file cmd.bat exist in temp folder then doesn't create new one, otherwise create a cmd.bat in temp folder. 在这里,我尝试检查是否在临时文件夹中存在cmd.bat文件,然后不创建新文件,否则在临时文件夹中创建cmd.bat文件。 But having problem with temp folder path "%temp%\\cmd.bat", it is displaying error :
但是临时文件夹路径“%temp%\\ cmd.bat”有问题,它显示错误:
Timestamp: 10/31/2012 3:21:40 AM
Error: NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]
Source File: chrome://myext/content/overlay.js
Line: 9
My code : 我的代码:
var chk_file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
chk_file.initWithPath("%temp%\cmd.bat");
if ( chk_file.exists() == false ) {
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var file = FileUtils.getFile("TmpD", ["cmd.bat"]);
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
}
else
{
alert("file already exists");
}
initWithPath takes full system path only. initWithPath仅采用完整的系统路径。
Use this to go to temp and then try 用这个去临时,然后尝试
var environment = Components.classes["@mozilla.org/process/environment;1"]
.getService(Components.interfaces.nsIEnvironment);
var path = environment.get("TEMP");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.