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
- Java 26 (JDK 26) Features with examples
- Top 10 Reasons to Learn Java in 2026
- JDK 26 Tutorial
- Java Certification Roadmap 2026: Which Oracle Certs Matter
- Install JDK 26: A Complete Beginner's Guide (2026)
- What Is Java? A Complete, Up-to-Date Guide for 2026
- Java 26 HTTP3 tutorial - HTTP 3 support in JDK 26 - How to use HTTP/3 in Java 26 application?
- JDK 28 Preview: Value Objects, Shenandoah GC & JSON API
- Java Tutorials


