【发布时间】:2016-11-15 06:32:45
【问题描述】:
我想跟踪目录中的新文件。我使用了文档中给出的脚本:http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener
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?
谢谢。
【问题讨论】: