当前位置: 代码迷 >> 综合 >> Electron-Vue代码集锦
  详细解决方案

Electron-Vue代码集锦

热度:57   发布时间:2024-01-28 11:14:09.0

1、获取文件夹选择框的值

<input type="file" webkitdirectory @change="getShps">
getShps (e) {// 获取元素的files属性来获取路径,使用元素的value获取的是C:\fakepath假目录console.log(e.target.files[0].path)
}

2、列出该绝对目录下的所有文件的绝对路径

import fs from 'fs'   
import path from 'path'
fileDisplay (basepath) {fs.readdir(basepath, (err, files) => {if (err) {console.warn(err)} else {// 遍历读取到的文件列表files.forEach((filename) => {// 获取当前文件的绝对路径let filedir = path.join(basepath, filename)// 根据文件路径获取文件信息,返回一个fs.Stats对象fs.stat(filedir, (error, status) => {if (error) {console.warn('获取文件stats失败')} else {// console.log(status)if (status.isFile()) { // 是文件// console.log(filedir)if (filedir.endsWith('.shp')) {this.fileList.push(filedir)this.fileState.push(false)}} else if (status.isDirectory()) { // 是文件夹this.fileDisplay(filedir)// 递归,如果是文件夹,就继续遍历该文件夹下面的文件}}})})}})}