我想写一个 node .js脚本,监视文件目录中的更改,然后打印更改的文件.如何修改此脚本,使其监视目录(而不是单个文件),并在目录中的文件发生更改时打印它们的名称?
var fs = require('fs'),
sys = require('sys');
var file = '/home/anderson/Desktop/fractal.png'; //this watches a file, but I want to watch a directory instead
fs.watchFile(file, function(curr, prev) {
alert("File was modified."); //is there some way to print the names of the files in the directory as they are modified?
});