我想跟蹤目錄中的新文件。我使用的文檔中提供的腳本:http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listenerNode.js:跟蹤目錄中的新文件
var fs = require('fs');
fs.watch('mydir/', function (event, filename) {
console.log('event is: ' + event);
if (filename) {
console.log('filename provided: ' + filename);
} else {
console.log('filename not provided');
}
});
我使用touch hello.txt
例如添加文件mydir/
。
運行腳本時,我沒有得到新的文件名,因爲發出的事件是rename
!!這是控制檯輸出。
event is: rename
filename not provided
我怎樣才能得到文件的新名稱hello.txt
?
謝謝。
由於robertklep。我目前正在使用Mac,這就是爲什麼我有問題與FS。我會切換看。 – htaidirt 2013-02-28 12:02:09
Mac也在這裏,同樣的問題,所以我希望'watch'能解決它:) – robertklep 2013-02-28 12:19:23