Javascript 需要使用node js从多个输出中获得单个数组
我有一个找到folderPath的代码 异步函数checkFileLoc(folderPath,depth){ 深度-=1; 让files=fs.readdirSync(folderPath); files=wait Promise.all( file.map(异步(文件)=>{ const filePath=path.join(folderPath,file); const stats=fs.statSync(文件路径); if(stats.isDirectory()&&depth>0){ 返回checkFileLoc(文件路径、深度); }else if(stats.isFile())返回文件路径; 否则返回null; }) ); 返回文件 .reduce((all,folderContents)=>all.concat(folderContents),[]) .filter((e)=>e!=null);Javascript 需要使用node js从多个输出中获得单个数组,javascript,node.js,async-await,promise,Javascript,Node.js,Async Await,Promise,我有一个找到folderPath的代码 异步函数checkFileLoc(folderPath,depth){ 深度-=1; 让files=fs.readdirSync(folderPath); files=wait Promise.all( file.map(异步(文件)=>{ const filePath=path.join(folderPath,file); const stats=fs.statSync(文件路径); if(stats.isDirectory()&&depth>0){
}检查在其他代码位置对
getFile
的调用。提醒:您实际上使用了sync函数readdirSync
和statSync
,并且根本不需要使用Promise。@Vikas,您应该保持简单,您的代码的哪一部分是异步的?