4
我正在使用nodejs Chokidar觀看文件夾 我只想監視添加,刪除xml文件。 我是Chokidar的新手,無法弄清楚。 我嘗試設置Chokidar忽略以匹配以.xml結尾的所有字符串,但它看起來像Chokidar忽略接受負的正則表達式的使用Chokidar觀察特定的文件擴展名
即使下面的例子不工作
watcher = chokidar.watch(watcherFolder, {
ignored: /[^l]$,
persistent: true,
ignoreInitial: true,
alwaysState: true}
);
有沒有辦法做到這個還是我必須添加過濾器到回調函數?
watcher.on('add', function(path) {
if (!/\.xml$/i.test(path)) { return; }
console.log('chokidar: add: ' + path);
});
watcher.on('unlink', function(path) {
if (!/\.xml$/i.test(path)) { return; }
console.log('chokidar: unlink: ' + path);
});
watcher.on('change', function(path) {
if (!/\.xml$/i.test(path)) { return; }
console.log('chokidar: change: ' + path);
});
也就是說,這真的很笨,我沒有嘗試過。 – Trevor
嘿傢伙,請看看我的問題:https://stackoverflow.com/questions/44530477/use-chokidar-for-watching-over-files-with-specific-extentions –