File tree Expand file tree Collapse file tree
24-Create-Node-JS-Command-Line-Tools/02-list Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,21 +8,23 @@ const util = require('util')
88// const lstat = util.promisify(fs.lstat)
99
1010// Method #3
11- // const { lstat } = fs.promises
11+ const { lstat } = fs . promises
1212
1313fs . readdir ( process . cwd ( ) , async ( err , filenames ) => {
1414 if ( err ) {
1515 console . log ( err )
1616 }
1717
18- for ( let filename of filenames ) {
19- try {
20- const stats = await lstat ( filename )
18+ const statPromises = filenames . map ( ( filename ) => {
19+ return lstat ( filename )
20+ } )
2121
22- console . log ( filename , stats . isFile ( ) )
23- } catch ( err ) {
24- console . log ( err )
25- }
22+ const allStats = await Promise . all ( statPromises )
23+
24+ for ( let stats of allStats ) {
25+ const index = allStats . indexOf ( stats )
26+
27+ console . log ( filenames [ index ] , stats . isFile ( ) ) ;
2628 }
2729} )
2830
You can’t perform that action at this time.
0 commit comments