# File filtering problem

**URL:** <https://forum.rclone.org/t/file-filtering-problem/5944>\
**Category:** Help and Support\
**Created:** [June 21, 2018, 5:30pm UTC](https://forum.rclone.org/t/file-filtering-problem/5944 "2018-06-21T17:30:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjnaz](https://forum.rclone.org/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cjnaz](https://forum.rclone.org/u/cjnaz)\
**Post date:** [June 21, 2018, 5:30pm UTC](https://forum.rclone.org/t/file-filtering-problem/5944/1 "2018-06-21T17:30:53Z")

</div>

I’m trying to find all RCLONE\_TEST files in the tree that are not beneath \*/RCloneSync/Test/.

The first command demonstrates that --exclude excludes all files from the directory, but when I then add the --include rclone is finding matches in the excluded directory. What is the correct way to do this?

```auto

[xxx RCloneSync]$ rclone lsl .. --exclude "RCloneSync/Test/" | grep TEST
      110 2018-03-14 21:34:18.367576724 RCloneSync/RCLONE_TEST
[xxx RCloneSync]$ rclone lsl .. --exclude "RCloneSync/Test/" --include RCLONE_TEST
      110 2018-03-14 21:34:18.367576724 RCloneSync/RCLONE_TEST
      110 2018-03-14 21:34:18.000000000 RCloneSync/Test/tests/test_remote_newer - Copy/initial/RCLONE_TEST
      110 2018-03-14 21:34:18.367576700 RCloneSync/Test/tests/test_remote_newer/initial/RCLONE_TEST
      110 2018-03-14 21:34:18.367576700 RCloneSync/Test/tests/test_all/initial/RCLONE_TEST

[xxx RCloneSync]$ rclone -V
rclone v1.37-157-g5a3a56ab\u03b2
- os/arch: linux/amd64
- go version: go1.9

```

---

<div class="post-metadata">

**Author:** ![cjnaz](https://forum.rclone.org/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cjnaz](https://forum.rclone.org/u/cjnaz)\
**Post date:** [June 21, 2018, 6:45pm UTC](https://forum.rclone.org/t/file-filtering-problem/5944/2 "2018-06-21T18:45:30Z")

</div>

My read of [https://rclone.org/filtering/#how-the-rules-are-used](https://rclone.org/filtering/#how-the-rules-are-used)

> Rclone maintains a combined list of include rules and exclude rules.
> 
> Each file is matched in order, starting from the top, against the rule in the list until it finds a match. The file is then included or excluded according to the rule type.

I read this as the exclude would be the first match for the files beneath the excluded directory.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [June 22, 2018, 9:19pm UTC](https://forum.rclone.org/t/file-filtering-problem/5944/3 "2018-06-22T21:19:32Z")

</div>

Note the [important section](https://rclone.org/filtering/#repeating-options) in the docs

> You should not use --include\* together with --exclude\*. It may produce different results than you expected. In that case try to use: --filter\*.

So rework your example into

```
rclone lsl .. --filter "- RCloneSync/Test/**" --filter "+ RCLONE_TEST" --filter "- *"

```

And it will hopefully do what you want!

> [@cjnaz](#):
>
> rclone v1.37-157

I suggest you try a newer rclone, say [1.42](https://rclone.org/downloads/) or [the latest beta](https://beta.rclone.org) too 🙂

It should also have printed this warning

```auto
$ rclone -v ls --include x --exclude x /tmp/test
2018/06/22 22:16:39 INFO : Using --filter is recommended instead of both --include and --exclude as the order they are parsed in is indeterminate

```

But I see the log level needs to be raised so it appears without `-v` so I've done that.

---

<div class="post-metadata">

**Author:** ![cjnaz](https://forum.rclone.org/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@cjnaz](https://forum.rclone.org/u/cjnaz)\
**Post date:** [June 22, 2018, 11:09pm UTC](https://forum.rclone.org/t/file-filtering-problem/5944/4 "2018-06-22T23:09:40Z")

</div>

Thanks Nick,  
Your recommendation is where I ended up.

Note that one cannot predictable use both --filter-from and --filter. With --dump filters I’m seeing that (something like) “+ /\*” always ends up at the top of the directory filter list, effectively blocking the \<- directories\> on the command line.

Luckily, for my application, I don’t need the --filter-from filtered items while at the same time doing the command line. If both --filter-from and command line --filter should play nice together then shall I file a bug?

In any case, an update to the Filtering docs page would be quite helpful, noting not to use both command line --include and --exclude together. I think the current doc says it should work.

FYI, I dropped in 1.42 beta and rclonesync still works fine. I’m adding test case support and need to ignore possible RCLONE\_TEST file mismatches in the test directories without tripping the access check fail. I’ll push an update to [https://github.com/cjnaz/RCloneSync](https://github.com/cjnaz/RCloneSync) within a couple days.

---

<div class="post-metadata">

**Author:** ![ncw](https://forum.rclone.org/user_avatar/forum.rclone.org/ncw/32/18_2.png) [@ncw](https://forum.rclone.org/u/ncw)\
**Post date:** [June 23, 2018, 5:58pm UTC](https://forum.rclone.org/t/file-filtering-problem/5944/5 "2018-06-23T17:58:06Z")

</div>

> [@cjnaz](#):
>
> Note that one cannot predictable use both --filter-from and --filter. With --dump filters I’m seeing that (something like) “+ /\*” always ends up at the top of the directory filter list, effectively blocking the \<- directories\> on the command line.
> 
> Luckily, for my application, I don’t need the --filter-from filtered items while at the same time doing the command line. If both --filter-from and command line --filter should play nice together then shall I file a bug?

If you just use one `-filter` and one `--filter-from` then things will be consistent, but if you use multiple then you run into the same problem of having multiple `--include` and `--exclude` statements.

I think that is probably covered in the docs: [Rclone Filtering](https://rclone.org/filtering/#repeating-options) both the order that things are processed in and the problems with multiple options.

> [@cjnaz](#):
>
> FYI, I dropped in 1.42 beta and rclonesync still works fine. I’m adding test case support and need to ignore possible RCLONE\_TEST file mismatches in the test directories without tripping the access check fail. I’ll push an update to [https://github.com/cjnaz/RCloneSync](https://github.com/cjnaz/RCloneSync) within a couple days.

Nice 😃

---

<div class="post-metadata">

**Author:** ![system](https://forum.rclone.org/uploads/default/original/2X/3/39ad3235f6ffec76ccd0c81616bd55697b4c300d.png) [@system](https://forum.rclone.org/u/system)\
**Post date:** [March 4, 2020, 12:45am UTC](https://forum.rclone.org/t/file-filtering-problem/5944/6 "2020-03-04T00:45:46Z")

</div>

Closed on March 4, 2020, 12:45am UTC


