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
12import { readdir , stat } from "fs/promises" ;
3+ import { join } from "path" ;
24
35export const getAllFiles = async ( dirPath , arrayOfFiles = [ ] ) => {
46 const files = await readdir ( dirPath ) ;
57
68 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 ) ;
1114 } else {
12- arrayOfFiles . push ( join ( dirPath , "/" , file ) ) ;
15+ arrayOfFiles . push ( filePath ) ;
1316 }
1417 }
1518
You can’t perform that action at this time.
0 commit comments