Home Javascript Javascriptexamples JavaScript move file
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript move file

Advertisement
This page discusses - JavaScript move file

JavaScript move file

        

In this section, we are going to move a file from one folder to another using JavaScript.

In the given example, firstly we have created an ActiveXObject object which is used to enable and return a reference to an Automation object. It takes the parameter 'servername' which represents the name of the application and 'typename' represents the type or class of object to create. Then, we have used the JavaScript method GetFile() with this object which returns the file with the specified path. To move the file from the specified location to another location, we have used JavaScript Move() method. This method takes a single parameter, destination, which represents the location to which the file is to be moved.

Here is the code:

<html>
<h2>Move file in JavaScript</h2>
<script>
function moveFile(){
var object = new ActiveXObject("Scripting.FileSystemObject");
var file = object.GetFile("C:\\My\\Hello.txt");
file.Move("C:\\MyFile\\");
document.write("File is moved successfully");
}
</script>
<form>
<input type="Button" value="Move File" onClick='moveFile()'>
</form>
</html>

When you load the above html code, you will get a button. On clicking the button, you will find that the file is moved to the destination path.

Download Source Code:

        

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Ask Questions?    Discuss: JavaScript move file  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
sabarish
December 16, 2011
REG: Move file

When I click the Move file button there's an error occured : "ActiveXObject is not defined"
DMCA.com