An electron-based WIP aesthetic file explorer ^^
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
FileKade/scripts/fileview/load/load.js

42 lines
1.7 KiB

3 years ago
const fs = require('fs');
const path = require('path');
const moment = require("../../dep/moment");
const fileIcon = require('../fileicon');
const trimext = require("../../../json/trimext.json");
const extensions = require("../../../json/extensions.json");
const getsize = require("../../fileview/filesize");
module.exports = () => {
let dir = window.kade.cpath;
let ldir = fs.readdirSync(dir);
for (const file of ldir) {
let ofile = {};
ofile.icon = fileIcon(`${dir}\\${file}`, file);
ofile.name = trimext.includes(path.extname(file)) ? file.slice(0, file.length - path.extname(file).length) : file;
try {ofile.type = fs.lstatSync(`${dir}\\${file}`).isDirectory() ? "File Folder" : (extensions[path.extname(file).slice(1)] || "File");}
catch {ofile.type = `${path.extname(file)} File`.trim();}
try {ofile.lastModified = new Date(fs.lstatSync(`${dir}\\${file}`).mtimeMs);}
catch {ofile.lastModified = 0;}
try {ofile.lastModifiedString = ofile.lastModified === 0 ? '' : moment(ofile.lastModified).format('M/D/YYYY, h:mm:ssa');}
catch {ofile.lastModifiedString = '';}
try {
if (fs.lstatSync(`${dir}\\${file}`).isFile()) {
ofile.size = fs.lstatSync(`${dir}\\${file}`).size;
ofile.sizeString = `${getsize(ofile.size)}`;
ofile.dir = false;
} else {
ofile.size = 0;
ofile.sizeString = '';
ofile.dir = true;
}
} catch {
ofile.size = 0;
ofile.sizeString = '';
ofile.dir = true;
}
window.kade.cdir.push(ofile);
}
};