-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.ts
More file actions
37 lines (31 loc) · 1.01 KB
/
Copy pathfile.ts
File metadata and controls
37 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import fs from 'fs'
export const nestedFolderSearch = (staticPath: string, subPath = '/') => {
const files = fs.readdirSync(staticPath)
const folders = [{ subPath, staticPath }]
for (const file of files) {
const stats = fs.statSync(staticPath + '/' + file)
if (!stats.isDirectory()) continue
const items = nestedFolderSearch(
staticPath + '/' + file,
subPath + file + '/'
)
for (const item of items) folders.push(item)
}
return folders
}
export const nestedFileSearch = (staticPath: string) => {
const folders = nestedFolderSearch(staticPath)
const files: { staticPath: string; subPath: string }[] = []
for (const folder of folders) {
const filesInFolder = fs.readdirSync(folder.staticPath)
for (const file of filesInFolder) {
const stats = fs.statSync(folder.staticPath + '/' + file)
if (stats.isDirectory()) continue
files.push({
staticPath: folder.staticPath + '/' + file,
subPath: folder.subPath + file
})
}
}
return files
}