File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change
1
+ // @ts -check
1
2
import { readdir , stat } from "fs/promises" ;
3
+ import { join } from "path" ;
2
4
3
5
export const getAllFiles = async ( dirPath , arrayOfFiles = [ ] ) => {
4
6
const files = await readdir ( dirPath ) ;
5
7
6
8
for ( const file of files ) {
7
- const { isDirectory } = await stat ( dirPath + "/" + file ) ;
8
- if ( isDirectory ( ) ) {
9
- const filesInDirectory = await getAllFiles ( dirPath + "/" + file , arrayOfFiles ) ;
10
- arrayOfFiles . push ( filesInDirectory ) ;
9
+ const filePath = join ( dirPath , file ) ;
10
+ const stats = await stat ( filePath ) ;
11
+ if ( stats . isDirectory ( ) ) {
12
+ const filesInDirectory = await getAllFiles ( filePath , arrayOfFiles ) ;
13
+ arrayOfFiles . concat ( filesInDirectory ) ;
11
14
} else {
12
- arrayOfFiles . push ( join ( dirPath , "/" , file ) ) ;
15
+ arrayOfFiles . push ( filePath ) ;
13
16
}
14
17
}
15
18
You can’t perform that action at this time.
0 commit comments