Skip to content

Commit

Permalink
Add loop-folder method
Browse files Browse the repository at this point in the history
  • Loading branch information
esotericenderman committed Sep 8, 2024
1 parent d34aad8 commit 4359407
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/functions/loop-folder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { readdirSync, readFileSync } from "fs"

export const loopFolder = (folderPath: string, callback: (filePath: string, fileContent: Buffer) => void) => {
try {
const folderFiles = readdirSync(folderPath);

for (const file of folderFiles) {
loopFolder(file, callback);
}
} catch (error) {
callback(folderPath, readFileSync(folderPath));
return;
}
}

0 comments on commit 4359407

Please sign in to comment.