76 lines
1.1 KiB
JavaScript
76 lines
1.1 KiB
JavaScript
|
|
|
||
|
|
#ifdef SERVER
|
||
|
|
|
||
|
|
import fs from "fs";
|
||
|
|
|
||
|
|
import path from "path";
|
||
|
|
|
||
|
|
#endif
|
||
|
|
|
||
|
|
|
||
|
|
import file from "./fileChooser.file.js";
|
||
|
|
|
||
|
|
export default class fileChooserFiles{
|
||
|
|
|
||
|
|
async open() {
|
||
|
|
|
||
|
|
var relativePath = "./";
|
||
|
|
|
||
|
|
var systemPath = await this.getSystemPath( relativePath )
|
||
|
|
|
||
|
|
var files = await this.getDirectory( systemPath );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
node async getSystemPath( relativePath ) {
|
||
|
|
|
||
|
|
var absolutePath = path.resolve( relativePath );
|
||
|
|
|
||
|
|
console.log("getSystemPath", absolutePath);
|
||
|
|
|
||
|
|
return absolutePath;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
node async getDirectory( absolutePath ) {
|
||
|
|
|
||
|
|
var files = fs.readdirSync( absolutePath );
|
||
|
|
|
||
|
|
|
||
|
|
for (var i = 0; i < files.length; i++) {
|
||
|
|
|
||
|
|
var filename = files[i];
|
||
|
|
|
||
|
|
var fileStat = fs.lstatSync( absolutePath + "/" + filename );
|
||
|
|
|
||
|
|
|
||
|
|
var currentFile = new file();
|
||
|
|
|
||
|
|
|
||
|
|
currentFile.filename = filename;
|
||
|
|
|
||
|
|
currentFile.path = absolutePath;
|
||
|
|
|
||
|
|
if( fileStat.isDirectory() ) {
|
||
|
|
|
||
|
|
currentFile.fileType = "directory";
|
||
|
|
|
||
|
|
} else {
|
||
|
|
|
||
|
|
currentFile.fileType = "file";
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log("add file", currentFile);
|
||
|
|
|
||
|
|
this.add( currentFile );
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log("readdirSync", files);
|
||
|
|
|
||
|
|
return files;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|