最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How to create new folder on desktop using Javascript? - Stack Overflow

programmeradmin7浏览0评论

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>

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>
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
Add a ment  | 

4 Answers 4

Reset to default 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

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)
}
发布评论

评论列表(0)

  1. 暂无评论