2016-09-28 91 views
0

我正在开发Angular2 + Electron桌面应用程序。作为样板我带着简单的例子Angular2 + Electron电子:从客户端获取文件夹结构

我需要拖&下降文件夹的面积得到的文件夹结构。我发现如何获取有关文件夹的信息,一旦它下降到区域。现在需要借助此信息获取文件夹结构。这里是一个返回对象的例子:

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

关于这个问题的任何信息将不胜感激!

回答

1

首先使用fs stats来检查这是否是一个目录。

然后使用fs node module读取文件夹中的可用文件和文件夹。

UPDATE

如果您使用的WebPack作为建设者,一定要建立target: "electron-renderer"webpack docs提及。

TS会投诉import * as fs from 'fs'。要解决这个问题

第一种方式是添加declare var require:any和使用const fs = require('fs') - 丑陋的黑客。

是添加节点分型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" 
    ] 
} 

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

相关问题