Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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();

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
Posted
Updated 31-Jan-12 20:46pm
v3
Comments
Rajesh Anuhya 1-Feb-12 2:46am    
Code tags added
--RA

Use try catch

C#
try
  {
  //Run some code here
  }
catch(err)
  {
  //Handle errors here
  }

http://www.w3schools.com/js/js_try_catch.asp[^]
 
Share this answer
 
Comments
Jijesh Balakrishnan b 1-Feb-12 1:33am    
it is not giving any exception.it is giving error message
CRDave1988 1-Feb-12 2:50am    
But it will Work For file not fount try this
<script language="javascript" type="text/javascript">


try
{
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
var fileName = fileSystem.GetFile("D:/hi.txt");

fileName.Delete();
alert("Success file deleted")

}
catch(exp)
{
alert("Fail : file not found");
}
//U can Countinu Here

</script>
Jijesh Balakrishnan b 1-Feb-12 3:06am    
thank you
Try this

XML
<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>


Thanks
--RA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900