2013-07-08 91 views
0

我不能從這裏得到的序列的例子,但我不能提供的鏈接(?):node.js的fs.readdir遞歸目錄搜索[2]

NodeJS: How would one watch a large amount of files/folders on the server side for updates?

var fs = require('fs'); 
var walk = function(dir, done) { 
    var results = []; 
    fs.readdir(dir, function(err, list) { 
    if (err) return done(err); 
    var i = 0; 
    (function next() { 
     var file = list[i++]; 
     if (!file) return done(null, results); 
     file = dir + '/' + file; 
     fs.stat(file, function(err, stat) { 
     if (stat && stat.isDirectory()) { 
      walk(file, function(err, res) { 
      results = results.concat(res); 
      next(); 
      }); 
     } else { 
      results.push(file); 
      next(); 
     } 
     }); 
    })(); 
    }); 
}; 

我已經試過這個來調用這個函數,但我不確定它需要什麼參數。有人可以請指教嗎?

//walk(process.env.HOME, function(err, results) { 
walk("C:\", function(err, results) { 
    if (err) throw err; 
    console.log(results); 
}); 

我得到的錯誤是

module.js:437 
    var compiledWrapper = runInThisContext(wrapper, filename, true); 
         ^
SyntaxError: Unexpected token ILLEGAL 
    at Module._compile (module.js:437:25) 
    at Object.Module._extensions..js (module.js:467:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Module.runMain (module.js:492:10) 
    at process.startup.processNextTick.process._tickCallback (node.js:244:9) 

回答

1

讓您遠離\。使用"C:\\"而不是"C:\"

+0

tks丹,現在沒有錯誤,但它只是坐在那裏,並沒有'console.log();'。這是在最低限度上等待的東西。 – HattrickNZ

+0

Doh !!這只是一個相當長的等待提供一個大文件。 TKS – HattrickNZ