Skip to content

Commit

Permalink
fix: empty directory error
Browse files Browse the repository at this point in the history
  • Loading branch information
salvatorecriscioneweb committed Dec 18, 2023
1 parent 3e19778 commit 64e6dea
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/utils/getExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ export async function hasSubfolders(_path: string) {
}
}

export async function isEmptyDirectory(_path: string) {
try {
const files = await fs.readdir(_path);
return files.length === 0;
} catch (err) {
if (err instanceof Error) {
console.log("Error checking directory Empty:", err.message);
throw err;
}
}
}

type FilesContent = Record<string, string | undefined>;

export async function processFiles(
Expand All @@ -42,7 +54,11 @@ export async function processFiles(
if (_hasSubfolders) {
result[file] = await processFiles(filePath, processCallback);
} else {
result[file] = await processCallback(filePath);
// Check if the directory is empty
const isEmpty = await isEmptyDirectory(filePath);
if (!isEmpty) {
result[file] = await processCallback(filePath);
}
}
}

Expand Down

0 comments on commit 64e6dea

Please sign in to comment.