Skip to content

Commit b0b3a6e

Browse files
committed
chore: add utility fn for dirs
1 parent d5c093c commit b0b3a6e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/utils/file.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ export function getFilesInDirectory(dirPath, fileExtensions = [], resolvePath =
4646
if (resolvePath) return fileNames.map((fileName) => path.resolve(dirPath, fileName));
4747
return fileNames;
4848
}
49+
50+
/**
51+
* Get list of directories contained in current directory.
52+
* @param {string} currentPath - current directory
53+
* @return {*}
54+
*/
55+
export function getDirectories(currentPath) {
56+
return fs
57+
.readdirSync(currentPath, { withFileTypes: true })
58+
.filter((dirent) => dirent.isDirectory())
59+
.map((dirent) => dirent.name);
60+
}

src/utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { deepClone } from "./clone";
55
import { refreshCodeMirror } from "./codemirror";
66
import {
77
formatFileSize,
8+
getDirectories,
89
getFilesInDirectory,
910
getProgrammingLanguageFromFileExtension,
1011
} from "./file";
@@ -88,4 +89,5 @@ export {
8889
generateName,
8990
filterEntityList,
9091
getFilesInDirectory,
92+
getDirectories,
9193
};

0 commit comments

Comments
 (0)