List files alternate
This commit is contained in:
parent
ee89506923
commit
2051ccee46
4 changed files with 24 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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) =>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue