Saturday, January 23, 2010

FindNewFiles, a Java class to poll a directory for new files

To get the most up to date version, download here.

Example usage:

...

FindNewFiles fnf;
ArrayList<java.util.File> newFiles;

try {
fnf = new FindNewFiles("/tmp"); /* or windows path */
} catch(Exception e) {
System.out.println("Exception: " + e.getMessage());
return;
}

while(true) {
/* get files which were not in the directory the previous time method was invoked */
newFiles = fnf.findNewFiles();
if(newFiles != null)
{
/* then found new files */
/* do something */
}

/* do something, perhaps sleep */
}

...

No comments:

Post a Comment