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.
Tutorials
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window


