Determine the status of the current file

const fs=require('fs');

fs.readdir(__dirname,(err,files)=>{     if(err) throw err;     // files stores all files in the current folder     console.log(files);     for(let i=0;i< files.length;i++){         // When reading files, the for loop executes normally         fs.stat(__dirname+'/'+files[i],(err,stats)=>{             // When the execution reaches that point, there is The for loop may be executed, this is the time i=files.length             if(stats.isFile()){                 console.log(files[i]+'is a file')             }else{                 console.log(files[i]+ 'Is a folder')             }         })     }













})

Guess you like

Origin blog.csdn.net/aa67567456/article/details/111464733