【问题标题】:Electron: Get folder structure from client sideElectron:从客户端获取文件夹结构
【发布时间】:2017-02-06 01:14:46
【问题描述】:

我正在开发 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: ""
}

任何有关此问题的信息将不胜感激!

【问题讨论】:

    标签: angular desktop-application electron


    【解决方案1】:

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

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

    更新

    如果您使用 webpack 作为构建器,请务必按照webpack docs 中的说明设置target: "electron-renderer"

    TS 会在import * as fs from 'fs' 投诉。

    解决此问题的第一种方法是添加 declare var require:any 并使用 const fs = require('fs') - 丑陋的 hack。

    第二是添加节点类型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';

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-20
      • 1970-01-01
      相关资源
      最近更新 更多