我在coffeescript中有以下代码递归列出目录(从javascript转换):
fs = require 'fs'
walk = (dir, done) ->
results = []
fs.readdir dir, (err, list) ->
return done(err) if err
pending = list.length
return done(null, results) unless pending
list.forEach (file) ->
file = "#{dir}\\#{file}"
fs.stat file, (err, stat) ->
if stat and stat.isDirectory()
walk file, (err, res) ->
results = results.concat(res)
done null, results unless --pending
else
results.push file
done null, results unless --pending
walk __dirname, (err, results) ->
throw err if err
console.log results
正如你所看到的,我正在使用list.forEach (file) ->
它并且它正在工作。但是当我尝试用for file in list
then 替换它时,它无法正常工作。我做错了什么?