views:

48

answers:

1

I am using JDK 7's WatchService to monitor directories.

The ENTRY_DELETE event tells me an entry has been deleted. I can get the name of that entry doing something similar to:

WatchEvent<Path> ev = cast(event);
Path name = ev.context();
Path child = dir.resolve(name);

I want to know if the deleted entry was a file or folder. Naturally, I tried child.isDirectory() but that didn't work, of course, because the element doesn't exist anymore.

Is there any way, without heuristics, telling if the deleted element was a file or a directory?

Thanks.

+1  A: 

Unfortunately, since WatchService is built on top of the native OS's file event service, it is limited by the information the native service provides. Linux's inotify does indicate what type of filesystem object was deleted, but Microsoft's FileSystemWatcher just gives the name.

Devon_C_Miller
Yes, I figured out that this is probably all it gets, but I thought maybe it scans the directory structure on startup or something like that, enabling it to tell files from folders when an event occurrs.I see the reference you gave is to a .net FileSystemWatcher, but I am using Java. This .net watcher has "rename" events, which are not supported by the NIO2.0 WatchService of JDK 7, as far as I know.Was your answer relevant to .net?If telling file from folder deletion can't be done, I'll just have to act as if both happened - and one of my operations will fail, and I'll ignore that.
shwartz