List files alternate

This commit is contained in:
Manav Rathi 2024-04-17 14:48:03 +05:30
parent ee89506923
commit 2051ccee46
No known key found for this signature in database
4 changed files with 24 additions and 0 deletions

View file

@ -27,3 +27,8 @@ export const fsIsDir = async (dirPath: string) => {
const stat = await fs.stat(dirPath);
return stat.isDirectory();
};
export const fsLsFiles = async (dirPath: string) =>
(await fs.readdir(dirPath, { withFileTypes: true }))
.filter((e) => e.isFile())
.map((e) => e.name);

View file

@ -20,6 +20,7 @@ import {
import {
fsExists,
fsIsDir,
fsLsFiles,
fsMkdirIfNeeded,
fsReadTextFile,
fsRename,
@ -134,6 +135,8 @@ export const attachIPCHandlers = () => {
ipcMain.handle("fsIsDir", (_, dirPath: string) => fsIsDir(dirPath));
ipcMain.handle("fsLsFiles", (_, dirPath: string) => fsLsFiles(dirPath));
// - Conversion
ipcMain.handle("convertToJPEG", (_, fileData, filename) =>

View file

@ -121,6 +121,9 @@ const fsWriteFile = (path: string, contents: string): Promise<void> =>
const fsIsDir = (dirPath: string): Promise<boolean> =>
ipcRenderer.invoke("fsIsDir", dirPath);
const fsLsFiles = (dirPath: string): Promise<boolean> =>
ipcRenderer.invoke("fsLsFiles", dirPath);
// - AUDIT below this
// - Conversion
@ -322,6 +325,7 @@ contextBridge.exposeInMainWorld("electron", {
readTextFile: fsReadTextFile,
writeFile: fsWriteFile,
isDir: fsIsDir,
lsFiles: fsLsFiles,
},
// - Conversion

View file

@ -205,6 +205,18 @@ export interface Electron {
* directory.
*/
isDir: (dirPath: string) => Promise<boolean>;
/**
* Return a list of the names of the files in the given directory.
*
* Note:
*
* - This is not recursive, it will only return the names of direct
* children.
*
* - It will return only the names of files, not directories.
*/
lsFiles: (dirPath: string) => Promise<string>;
};
/*