【发布时间】:2021-05-19 18:02:12
【问题描述】:
我想看,文件夹的变化:
- test/index.js
- te3st/index.js
但不会改变
- te2st/index.js 不是任何 teNUMBERst/index.js
我使用 chokidar 并从这里获得灵感:chokidar
ignored: ignored: /^.*\b(?:(?!te2st\/index\.js)\w)+\b$/ 可以使用正则表达式,但我的正则表达式没有像预期的那样工作 (regex how to exclude specific characters or string anywhere)。
这个正则表达式在这里工作: https://regex101.com/r/XnKYcf/1/
var chokidar = require('chokidar');
var watcher = chokidar.watch('/home/replays/0.0.24/t*t/index.js',
{ignored: /^.*\b(?:(?!te2st\/index\.js)\w)+\b$/, persistent: true});
watcher
.on('add', function(path) {console.log('File', path, 'has been added ');})
.on('change', function(path) {console.log('File', path, 'has been changed ');})
.on('unlink', function(path) {console.log('File', path, 'has been removed ');})
.on('error', function(error) {console.error('Error happened', error);})
这是广告否定定义,在这里还不能正常工作。通过正则表达式允许会更实用且更易于阅读。这可能吗?
【问题讨论】:
-
暂时的解决方法:
crontab -e*/2 * * * * php ~/doIt.php读取由正则表达式过滤的完整文件夹
标签: javascript chokidar