1

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?)

user1068636
  • 1,871
  • 7
  • 33
  • 57
  • 1
    The simplest way is to use code similar to [this](http://stackoverflow.com/a/16251508/2071828) to filter the events. – Boris the Spider Jun 12 '15 at 15:47
  • set `recursive` to false???????? – ZhongYu Jun 12 '15 at 15:57
  • Note that you won't notification about the nested file being created. You'll get a EVENT_MODIFY because the last modified date of the containing folder (which is in the directory you're watching) was changed. You can choose to ignore EVENT_MODIFY for directory paths. – Sotirios Delimanolis Jun 12 '15 at 15:58
  • Boris I cannot do this because the directory structure I am dealing with is in the order of terabytes. Simply put I don't have the resources to watch the entire directory recursively and filter out the events I don't care about – user1068636 Jun 12 '15 at 17:25
  • Bayou.io please clarify. How exactly do I set recursive to false? – user1068636 Jun 12 '15 at 17:25

0 Answers0