3

How to create a new folder on desktop by using JavaScript after a button is clicked?

My Scenario :

  1. I want to create a button that user can click.
  2. When user click on the button, a folder will be created on the user's desktop.

Here is the code (that I have found after a several research) that I use to try to do the scenario above.

<html>
<body>
  <script>
    function create() {
      var fso = new ActiveXObject("Scripting.FileSystemObject");
      fso.CreateFolder("C:\\Temp\\myFolder");
      fso = null;
    }
  </script>
  Create Folder: "c:\newfolder"
  <form name="myForm">
    <input type="Button" value="Click to Create New Folder" onClick="create()">
  </form>
</body>
</html>
AsthaUndefined
  • 1,111
  • 1
  • 11
  • 24
liana
  • 33
  • 1
  • 1
  • 3
  • 1
    This is intentionally not possible with javascript running in the browser - see https://stackoverflow.com/a/372333/1136527 – Alex McMillan Nov 13 '18 at 04:02
  • 1
    ActiveX is IE only and modern day IE basically disables it.... so not going to happen. If you are building an application for you to run, you can build yourself a node app that does this. – epascarello Nov 13 '18 at 04:03

4 Answers4

7

with javascript alone this move will create a security problem and I don't think it's possible to do. But on server side with some tool like Node.js you can by doing something like:

var fs = require("fs");
fs.mkdir("<your path>",callback);

manipulating client file with your js code often create security issues

Moussa
  • 461
  • 4
  • 14
0

No you can't do this using native Javascript.Native Javascript won't allow you to do any I/O in browser. But if its your necessary requirement then I would suggest you to use any server side tool like node.js. How to do in node.js?,You can get reference from @Moussa answer.

Vaibhav
  • 49
  • 1
  • 4
0

I used the library java.io.File and it worked!

var file = new java.io.File("E:\\YourNewFolder");
var path = file.mkdir();
fcdt
  • 2,371
  • 5
  • 14
  • 26
-4

Try This Code

createFolder("C:\\TEST\\")
function createFolder(folder){
makeDir(folder)
}
Mukesh Prajapati
  • 786
  • 1
  • 6
  • 12