相关疑难解决方法(0)

使用node.js观察文件夹以进行更改,并在更改时打印文件路径

我正在尝试编写一个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?
});
Run Code Online (Sandbox Code Playgroud)

node.js

77
推荐指数
3
解决办法
5万
查看次数

标签 统计

node.js ×1