GetFile的返回值 [英] return value of GetFile
本文介绍了GetFile的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个javascript程序,用于删除文件,如下所示,
hi all,
I have a javascript program to delete a file as follows,
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
var fileName = fileSystem.GetFile("D:/hi.xml");
fileName.Delete();
如果在指定的位置不存在"hi.xml",那么脚本将给出错误消息找不到文件",并且该脚本将停止执行.但是在这里,我想继续执行.是否有任何方法可以检查加载是否成功?
我该如何移动?
请帮助我
if "hi.xml" is not there in that specified location, then the script is giving an error message as "file not found", and it stops the execution.but here i want to continue the execution.is there any method to check whether the loading is success ot not?
how can i move with this?
please help me
推荐答案
使用try catch
Use try catch
try
{
//Run some code here
}
catch(err)
{
//Handle errors here
}
http://www.w3schools.com/js/js_try_catch.asp [
http://www.w3schools.com/js/js_try_catch.asp[^]
尝试一下
Try this
<html>
<body>
<script language="JScript">
<!--
function remove()
{
var myObject;
myObject = new ActiveXObject("Scripting.FileSystemObject");
var f = myObject.GetFile("c:\\test.txt");
f.Delete();
}
//-->
</script>
Delete file "mytest.txt".
<form name="myForm">
<input type="Button" vvalue="Delete File" onClick='remove()'>
</form>
</body>
</html>
谢谢
--RA
Thanks
--RA
这篇关于GetFile的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文