1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| import net.contentobjects.jnotify.*;
public class SurveillanceFichiers implements JNotifyListener {
public SurveillanceFichiers (){
// Recuperation du repertoire de travail
String path = "/home/user";
System.out.println ("Surveillance de "+path);
//Pour savoir ce qu'on va surveiller (ici tout)
int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED | JNotify.FILE_MODIFIED | JNotify.FILE_RENAMED;
boolean surveilleSousRepertoire = true; // Pour surveiller ou non les sous repertoires
try {
int watchID = JNotify.addWatch(path, mask, surveilleSousRepertoire, this);
} catch (JNotifyException ex) {
ex.printStackTrace();
}
try {
Thread.sleep(1000000);
} catch (InterruptedException e1) {
}
}
public void fileRenamed(int wd, String rootPath, String oldName, String newName) {
System.out.println("file Renomme");
}
public void fileModified(int wd, String rootPath, String name) {
System.out.println("file Modif");
}
public void fileDeleted(int wd, String rootPath, String name) {
System.out.println("file Delet");
}
public void fileCreated(int wd, String rootPath, String name) {
System.out.println("file cree");
}
public static void main (String args []){
new SurveillanceFichiers ();
}
} |
Partager