[英]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.