我正在尝试编写一个 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?
});