开发者

How can I tell file deletion from directory deletion using JDK 7?

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 any more.

Is there any way, without heuristics, telling if the deleted开发者_Python百科 element was a file or a directory?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜