Is there way to watch a directory in Java 7 non-recursively?

69 Views Asked by At

Suppose I have a directory structure like so:

- dir1
  --dir1.1
    ---file1.2.1.txt
    ---file1.2.2.txt
  --dir1.2
- dir2
  --dir2.1
  --file2.1

Now suppose I create a new file "file1.1.txt" within the directory structure below:

- dir1
  --dir1.1
    ---file1.2.1.txt
    ---file1.2.2.txt
  --dir1.2
  --file1.1.txt
- dir2
  --dir2.1
  --file2.1

Using the code found here I can watch directory "dir1" and get a notification for when "file1.1.txt" has been created.

Suppose I create a file "file1.2.3.txt" within the directory structure below:

- dir1
  --dir1.1
    ---file1.2.1.txt
    ---file1.2.2.txt
    ---file1.2.3.txt
  --dir1.2
  --file1.1.txt
- dir2
  --dir2.1
  --file2.1

Again the same code found here will recursively watch the entire "dir1" and tell me as soon as "file1.2.3.txt" has been created.

How do I prevent the watch service from watching changes in sub directories (i.e. how do I restrict the watch service to just the current directory level and not watch recursively?)

0

There are 0 best solutions below