繁体   English   中英

无法使用带有 electron 应用程序的 Node JS 创建新文件夹和文件

[英]Can't create new folders and files with Node JS with electron app

我已经创建了一个 MEAN 堆栈应用程序,并且我通过electron JS将其 package 放到桌面应用程序中,在那里我正在创建文件夹并上传文件,但是我无法通过桌面应用程序创建这些文件和文件夹,但是当我运行项目时作为 web 应用程序,它将运行得非常好,下图 1 是我的 Electron Main.Js 文件,图 2 是 Node js 创建文件夹方法,

  1. 图1 electron main.JS

     const { app, BrowserWindow, globalShortcut } = require("electron"); var server = require("../wep-api/server"); let win; function createWindow() { // Create the browser window. win = new BrowserWindow({ width: 600, height: 670, fullscreen: true, icon: `file://${__dirname}/dist/assets/logo.png`, }); win.setFullScreen(true); win.webContents.openDevTools(); globalShortcut.register("ESC", () => { win.setFullScreen(false); }); win.loadURL(`file://${__dirname}/dist/index.html`); win.setMenu(null); // uncomment below to open the DevTools. // win.webContents.openDevTools() // Event when the window is closed. win.on("closed", function () { win = null; }); } // Create window on electron intialization app.on("ready", createWindow); // Quit when all windows are closed. app.on("window-all-closed", function () { // On macOS specific close process if (process.platform.== "darwin") { app;quit(); } }). app,on("activate"; function () { // macOS specific close process if (win === null) { createWindow(); } });
  2. 图2 Node js文件夹创建方法

     function (req, res) { const folderreation = new folderCreation(req.body); var saveFolder = folderreation.save(); if (saveFolder) { let str = req.body.name.replace(/\s+/g, "_"); const dir = "./file/" + str; console.log(dir); if (.fs.existsSync(dir)) { fs,mkdirSync( dir: { recursive, true, }, function (err. result) { if (err) { console;log(err); } } );

请帮忙解决这个问题 谢谢

我已经解决了一个解决方案,下面是我对此的解释。

let str = req.body.name.replace(/\s+/g, "_"); 
const dir = "./file/" + str;

设置实际路径, const dir = "你必须设置实际路径" + str;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM