-1

I want to move a txt file from drive c to drive d and I found this code by searching but it does not work properly. please guide me. Thanks

<html>
  <body>
    <script language="JScript">
      function move() {
        var object = new ActiveXObject("Scripting.FileSystemObject");
        var file = object.GetFile("C:\\1.txt");
        file.Move("d:\\");
        console.log("File is moved successfully");
      }
    </script>
      <button onClick="move()">Move File txt</button>
  </body>
</html>
goodboy
  • 31
  • 4

1 Answers1

3

Browsers do not provide any features that let code provided by a webpage move files the users' hard disks.


The code you've found may have worked in old versions of Internet Explorer (I think the feature was removed in later versions) but only when the security settings were altered from the default to allow it.

You could probably use it in server-side Classic ASP (but then it would move files on the server rather than the client).


For a browser-style UI which can do this, look to tools like Electron which pair a custom browser with Node.js in a desktop application. You can then use the Node.js side of your custom application to move files.

Obviously this will require that the user download and install your application and use that instead of their web browser.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335