public void watchDirectoryTree ( Path dir ) { if ( _watchedDirectories == null ) { throw new IllegalStateException ( "DirectoryWatcher.close() was called. Please make a new instance." ) ; } try { if ( Files . exists ( dir ) ) { Files . walkFileTree ( dir , new SimpleFileVisitor < Path > ( ) { @ Override public FileVisitResult preVisitDirectory ( Path dir , BasicFileAttributes attrs ) throws IOException { watchDirectory ( dir ) ; return FileVisitResult . CONTINUE ; } } ) ; } } catch ( IOException e ) { throw new RuntimeException ( e ) ; } }
Walk the directories under given path and register a watcher for every directory .