Refactor file management functions.

This commit is contained in:
Spencer Ofwiti 2021-05-26 10:00:08 +03:00
parent 7ddca00871
commit 3a6d3bb8c2

View File

@ -53,26 +53,26 @@ function isRoot(): boolean {
}
function getImages(): void {
// const cwd = process.cwd();
// fs.readdir('.', { withFileTypes: true }, ((err, files) => {
// if (!err) {
// const re = /(?:\.([^.]+))?$/;
// const images = files.filter(file => file.isFile() && ['jpg', 'png'].includes(re.exec(file.name)[1])).map(file => `file://${cwd}/${file.name}`);
// mainWindow.webContents.send('getImagesResponse', images);
// }
// }));
const cwd = process.cwd();
fs.readdir('.', { withFileTypes: true }, ((err, files) => {
if (!err) {
const re = /(?:\.([^.]+))?$/;
const images = files.filter(file => file.isFile() && ['jpg', 'png'].includes(re.exec(file.name)[1])).map(file => `file://${cwd}/${file.name}`);
mainWindow.webContents.send('getImagesResponse', images);
}
}));
}
function getDirectory(): void {
// fs.readdir('.', { withFileTypes: true }, (err, files) => {
// if (!err) {
// const directories = files.filter(file => file.isDirectory()).map(file => file.name);
// if (!isRoot()) {
// directories.unshift('..');
// }
// mainWindow.webContents.send('getDirectoryResponse', directories);
// }
// });
fs.readdir('.', { withFileTypes: true }, (err, files) => {
if (!err) {
const directories = files.filter(file => file.isDirectory()).map(file => file.name);
if (!isRoot()) {
directories.unshift('..');
}
mainWindow.webContents.send('getDirectoryResponse', directories);
}
});
}
// This method will be called when Electron has finished