4

I need to detect rename event of a particular file/directory. I am using chokidar - this one triggers unlink and add events, thus it is not possible to use it.

I also tried fs.watch - this one triggers two rename events, but unfortunately first one contains original name and the second one contains new name - this approach makes it unreliable in case many renames are triggered at the same time.

Snippet of fs.watch I use:

fs.watch(folder, function (event, filename) {
    console.log('event: ' + event);
    console.log('filename: ' + filename);
});  

Is there any reliable way (ideally one rename event which has 2 arguments - original name and new name) in Node.js to detect file/directory rename?

michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63

0 Answers0