Search code examples
javafilefilesystemwatchertemporary

FileSystemWatcher: Ignore temporary and ghost files created


I have implemented a watcher service in java which monitors folders for changes. Whenever a word file gets created,modified or deleted, it creates a lot of temporary files and ghost files. My question is how to ignore these files? I tried to see if they are hidden files, but they are not. I want a solution which works with all kind of applications not just microsoft word.

Thanks


Solution

  • My quick test shows the opposite: both the DOS shell and the Java IO API says that Word tmp files are hidden, ie.:

    DIR /A:H 
    

    lists Word tmp files.

    The following simple test program reports Word tmp files as hidden ones:

    import java.io.File;
    
    public class Hidden{
       public static void main(String[] args){
          File dir = new File(args[0]);
          for (File file : dir.listFiles()){
             System.out.println(file + " is hidden? " + file.isHidden());
          }     
       }
    }
    

    Test env: WinXP Professional + JDK 1.6