Chokidar: watcher firing 'add' events for existing files

Created on 9 Oct 2014  路  2Comments  路  Source: paulmillr/chokidar

this will list all current files in a directory

var chokidar = require('chokidar')
var watcher  = chokidar.watch('./public/images', {persistent: true})

watcher.on('add', function(path){
  console.log(path, ' added')
})

if I use the ignoreInitial option like so, it will skip initial files, but will print them again when a new file is added

var chokidar = require('chokidar')
var watcher  = chokidar.watch('./public/images', {persistent: true, ignoreInitial: true})

watcher.on('add', function(path){
  console.log(path, ' added')
})

related to #110, I'm using linux

Most helpful comment

I have the same issue on macOS currently.

With the code
watcher.on('add', path => { logger.debug('added file %s', path); });
I do get:

  • all files in the watched folder, when one file is added
  • all remaining files, when one file is deleted

When I add ignoreInitial (even given I don't want this for my case), it ignores the first watch round, but gives me all files when a file is added or removed.

All 2 comments

I was able to reproduce the problem, and then try again after merging the changes in #124. Master branch appears to behave correctly now.

I have the same issue on macOS currently.

With the code
watcher.on('add', path => { logger.debug('added file %s', path); });
I do get:

  • all files in the watched folder, when one file is added
  • all remaining files, when one file is deleted

When I add ignoreInitial (even given I don't want this for my case), it ignores the first watch round, but gives me all files when a file is added or removed.

Was this page helpful?
0 / 5 - 0 ratings