fs.watch blocks folder (windows 8) #3963

Closed
ArtemGovorov opened this Issue Sep 4, 2012 · 5 comments

3 participants

@ArtemGovorov

On windows 8 running following code

require('fs').watch('C:/Test');
require('fs').watch('C:/Test/Sub/SubSub');

and trying to rename C:/Test/Sub causes error:

Folder In Use The action can't be completed because the folder or a file in it is open in another program

@bnoordhuis
Node.js Foundation member

That's a limitation of the Windows file watcher API. Use fs.watchFile() if you don't want that.

@bnoordhuis bnoordhuis closed this Sep 4, 2012
@piscisaureus

I wish we would be able to work around this, but unfortunately we can't.

@ArtemGovorov

System.IO.FileSystemWatcher in .NET uses the same API (ReadDirectoryChangesW) and it works for given scenario. Could you elaborate please why is that impossible?

@piscisaureus

ReadDirectoryChangesW (apparently) locks the parent folder of the folder being watched.

You can even replicate this with windows explorer.

  • Create folder c:\a\b
  • Open that folder in windows explorer
  • Try to rename c:\a

System.IO.FileSystemWatcher in .NET uses the same API (ReadDirectoryChangesW) and it works for given scenario.

I don't believe you. Convince me by sharing your test case :-)

@ArtemGovorov

Windows explorer actually works fine on Windows 7-8, opened sub-folder explorer just updates the path. Though I can replicate what you're talking about on XP.

Regarding FileSystemWatcher, you're right, I tried to set up some basic test and realised that it does also block parent folder of the folder being watched. Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment