2

在 Windows 上测试。观察文件夹中的变化a。当我将监视文件夹重命名ab WatchService静止轨道更改时。问题是那a已经不存在了。(Path)event.context()返回监视文件夹的相对路径。因此,您现在正在观看a文件夹和文件abc.txt已更改。但实际上它是放在文件夹中的b

如何获得更改文件的正确绝对路径?

4

1 回答 1

0

I have confirmed your issue on Windows 7. After changing the (watched) dir name, events are reported such that the associated file name is resolved with the original dir name. This is also the case when using jpathwatch: http://jpathwatch.wordpress.com/ or https://sourceforge.net/projects/jpathwatch/

Typically you are watching a "known" or "expected" directory such as "/myDropBox", that is not expected to change names. It would seem that if you expect that a watched dir might change its name then you would also need to register its parent directory. You would then see a "delete" event for the original name and "create" for the new name.

于 2013-10-02T17:28:11.187 回答