Javascript FSO Move Method

Updated on 30 Mar 2012,
Published on 30 Dec 2008

File Object and Folder object returned by the GetFile and GetFolder of Javascript FileSystemObject (FSO) provide the access to the Move method that performs the action similar to cut and paste function of windows. FSO Move method moves the specified file to other specified location at client’s PC. Destination path of FSO Move method does not support wild card characters.

Syntax for FSO Move Method

fileObj.Move( destination );

// or
folderObj.Move( destination )

Above syntax for FSO Move method shows that it accepts only one parameter:

destination: this parameter accepts the destination path for the specified file where it is to be moved.

Example 1

File object to execute the Move Method

<script type="text/javascript">
    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // object created for file object returned by GetFile method
    var fileObj = fso.GetFile("C:\\Temp\\copy_of_textfile.txt");

    fileObj.Move("C:\\Temp\\myFolder\\copy_of_textfile.txt");
</script>

Example 2

Folder object to execute the Move Method

<script type="text/javascript">
    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // object created for folder object returned by GetFolder method
    var folderObj = fso.GetFolder("C:\\Temp\\copy_of_myFolder");

    folderObj.Move("C:\\Temp\\myFolder\\copy_of_myFolder")
</script>

Continue to next tutorial: Javascript FSO Files Collection to learn how to get the collection of file at the specified location.

4 Responses to "Javascript FSO Move Method"
Ajay
Are any permissions required to execute this method?
As i m getting permission denied while i run this .
Ezineasp.net
Hi Ajay
You must enable the Javascript of your web browser to work with FSO i.e. filesysteobject of javascript.

See here: How to enable JavaScript in Microsoft Internet Explorer 6 and 7
Ebi
I have been trying your script but that nothing happened..why??thank's...
The following example is more generic :

<script type="text/javascript" language="javascript">
// initialize ActiveXObject and
// create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject("Scripting.FileSystemObject");

fn="copy_of_textfile.txt"

// object created for file object returned by GetFile method
var fileObj = fso.GetFile("C:\\TMP\\TMP\\"+fn);

// One of the following
// RESPECT THE TWO TERMINAL BACKSLASHES if folder

fileObj.Move("C:\\TMP\\");
// or
// fileObj.Move("C:\\TMP\\"+fn);

</script>
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers