I'm using Linux (2.6) and Java6.
Es:
JNotify watches tree from folder TestDir
|-- TestDir
| `-- d1
| `-- f1
then I rename d1 in d2 an than f1 in f2, this is the log:
FileRenamed: oldName=d1, newName=d2
FileRenamed: oldName=d1/f1, newName=d1/f2
as you can see the second log-line trace old dir name "d1" and not the new "d2".
Code example:
import java.io.File;
import javax.swing.JOptionPane;
import net.contentobjects.jnotify.JNotify;
import net.contentobjects.jnotify.JNotifyException;
import net.contentobjects.jnotify.JNotifyListener;
/**
*
* @author franco
*/
public class CMain {
/**
* @param args the command line arguments
* @throws JNotifyException
*/
public static void main(String[] args) throws JNotifyException {
File _fpath = new File(System.getProperty("user.home"),"Projects/Tests/Test_JNotifyPrj/TestDir");
int _mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED | JNotify.FILE_MODIFIED | JNotify.FILE_RENAMED;
boolean _watchSubtree = true;
int _watchID = JNotify.addWatch(_fpath.toString(),_mask,_watchSubtree, new JNotifyListenerImpl());
JOptionPane.showMessageDialog(null,"Exit");
boolean _res = JNotify.removeWatch(_watchID);
if(!_res) {
System.err.println("Invalid watch ID specified: "+_watchID);
}
}
}
/**
*
* @author franco
*/
class JNotifyListenerImpl implements JNotifyListener {
public void fileCreated(int wd, String rootPath, String name) {
System.out.format("FileCreated: wd=%d, rootPath=%s, name=%s%n",wd,rootPath,name);
}
public void fileDeleted(int wd, String rootPath, String name) {
System.out.format("FileDeleted: wd=%d, rootPath=%s, name=%s%n",wd,rootPath,name);
}
public void fileModified(int wd, String rootPath, String name) {
System.out.format("FileModified: wd=%d, rootPath=%s, name=%s%n",wd,rootPath,name);
}
public void fileRenamed(int wd, String rootPath, String oldName, String newName) {
System.out.format("FileRenamed: wd=%d, rootPath=%s, oldName=%s, newName=%s%n",wd,rootPath,oldName,newName);
}
}