We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我照着你的写,但只能编译同一个目录下的一个文件,然后我在想可能没有循环,我认为应该类似这样的: `function travel(dir,callback,finish){ //异步读取目录 fs.readdir(dir,function(err,files){ //将0传给next,开始递归 for(i=0;i<files.length;++i) { (function next(i){ //如果当前未完成遍历 if (i<files.length){ //获取到路径文件名 var pathname = path.join(dir, files[i]); //异步获取此路径文件名的文件状态 fs.stat(pathname,function(err,stats){ //如果此文件是目录 if (stats.isDirectory()){ //再次递归此目录 travel(pathname, callback, function () { //如果此目录递归完了,继续检查上一层的下一个文件 next(i + 1); }); } //此文件是非目录 else { //执行上层所需的callback函数,完成后继续递归此层的下一个文件 callback(pathname,function(){ next(i + 1); }) } }) } //如果所有文件已经完成遍历 else{ //如果有完成回调函数,执行完成回调函数 finish && finish(); } }(i)) } }) }
travel("./",function(pathname){ console.log(pathname); })`
The text was updated successfully, but these errors were encountered:
No branches or pull requests
我照着你的写,但只能编译同一个目录下的一个文件,然后我在想可能没有循环,我认为应该类似这样的:
`function travel(dir,callback,finish){
//异步读取目录
fs.readdir(dir,function(err,files){
//将0传给next,开始递归
for(i=0;i<files.length;++i) {
(function next(i){
//如果当前未完成遍历
if (i<files.length){
//获取到路径文件名
var pathname = path.join(dir, files[i]);
//异步获取此路径文件名的文件状态
fs.stat(pathname,function(err,stats){
//如果此文件是目录
if (stats.isDirectory()){
//再次递归此目录
travel(pathname, callback, function () {
//如果此目录递归完了,继续检查上一层的下一个文件
next(i + 1);
});
}
//此文件是非目录
else {
//执行上层所需的callback函数,完成后继续递归此层的下一个文件
callback(pathname,function(){
next(i + 1);
})
}
})
}
//如果所有文件已经完成遍历
else{
//如果有完成回调函数,执行完成回调函数
finish && finish();
}
}(i))
}
})
}
travel("./",function(pathname){
console.log(pathname);
})`
The text was updated successfully, but these errors were encountered: