简体   繁体   English

电子:从客户端获取文件夹结构

[英]Electron: Get folder structure from client side

I am developing Angular2+Electron desktop application. 我正在开发Angular2 + Electron桌面应用程序。 As boilerplate I took simple example Angular2 + Electron 作为样板,我以简单的示例Angular2 + Electron为例

I need to get folder structure by drag & drop folder to the area. 我需要通过文件夹拖放到该区域来获取文件夹结构。 I found the way how to get information about folder once it dropped to area. 我找到了将文件夹放到区域后如何获取有关该文件夹的信息的方法。 Now need to get folder structure with a help of this info. 现在需要在此信息的帮助下获取文件夹结构。 Here is an example of returning object: 这是返回对象的示例:

{
  lastModified: 1460044264000,
  lastModifiedDate: "Thu Apr 07 2016 18: 51: 04 GMT + 0300(EEST)",
  name: "dna",
  path: "/Users/myUser/Pictures/folder",
  size: 340,
  type: "",
  webkitRelativePath: ""
}

Any information on this issue will be appreciated! 关于此问题的任何信息将不胜感激!

First of all use fs stats to check if that is a directory. 首先使用fs stats检查该目录。

Then use fs node module to read available files and folders in the folder. 然后使用fs节点模块读取文件夹中的可用文件和文件夹。

UPDATE 更新

If you use webpack as builder be sure to set up target: "electron-renderer" as mentioned in webpack docs . 如果您使用webpack作为构建器,请确保按照webpack docs中所述设置target: "electron-renderer"

TS would complain at import * as fs from 'fs' . TS会在import * as fs from 'fs'抱怨import * as fs from 'fs'

First way to solve this issue is to add declare var require:any and use const fs = require('fs') - ugly hack. 解决此问题的第一种方法是添加declare var require:any并使用const fs = require('fs') -丑陋的hack。

Second is to add node typings typings install dt~node -GS , configure tsconfig.json as: 第二种是添加节点typings install dt~node -GS ,类型tsconfig.json typings install dt~node -GS ,将tsconfig.json配置为:

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": true
  },
  "exclude": [
    "node_modules"
  ],
  "filesGlob": [
    "./src/customDefinitions.d.ts",
    "./src/app/**/*.ts",
    "!./node_modules/**/*.ts",
    "typings/index.d.ts"
  ]
}

And use import * as fs from 'fs'; 并使用import * as fs from 'fs';

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

相关问题 如何从客户端上传文件并将其保存到项目文件夹位置 - How to upload files and save to the projects folder location from client side 关于 ipc 事件的 Electron-Angular 打开客户端对话框 - Electron-Angular open client-side dialog on ipc event Electron - 如何从 BrowserWindow 获取授权令牌到主 Electron 应用程序 - Electron - how to get an auth token from BrowserWindow to the main Electron App 电子/角度应用程序可以访问文件夹中的视频。 - electron/angular app get access to videos in a folder. 在现有 Git 存储库上创建客户端/服务器文件夹结构 - Create client / server folder structure on existing Git repo 将Angular 2和Webpack添加到现有服务器/客户端文件夹结构中 - Adding Angular 2 & Webpack to an existing server/client folder structure 在客户端下载压缩文件夹在 angular+node (MEAN) 中不起作用 - Downloading a compressed folder on client side not working in angular+node (MEAN) 如何在客户端获取用户角色? - How to get user role on client side? 如何获得服务器端分页但客户端排序 - how to get server side pagination but client side sorting 从 Electron 应用程序获取链接以在 Chrome 中打开 - Get Link to open in Chrome from Electron application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM