How to create a new folder on desktop by using JavaScript after a button is clicked?
My Scenario :
- I want to create a button that user can click.
- 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>
How to create a new folder on desktop by using JavaScript after a button is clicked?
My Scenario :
- I want to create a button that user can click.
- 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>
Share
Improve this question
edited Nov 13, 2018 at 4:46
AsthaUndefined
1,1091 gold badge11 silver badges24 bronze badges
asked Nov 13, 2018 at 3:46
lianaliana
431 gold badge1 silver badge3 bronze badges
2
- 1 This is intentionally not possible with javascript running in the browser - see stackoverflow./a/372333/1136527 – Alex McMillan Commented Nov 13, 2018 at 4: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 Commented Nov 13, 2018 at 4:03
4 Answers
Reset to default 7with 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
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.
I used the library java.io.File
and it worked!
var file = new java.io.File("E:\\YourNewFolder");
var path = file.mkdir();
Try This Code
createFolder("C:\\TEST\\")
function createFolder(folder){
makeDir(folder)
}