Share on Google+Share on Google+

JavaScript move file

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:

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

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:



Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

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.

Discuss: JavaScript move file  

Post your Comment

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

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