Hello,
Is there any way to include or exclude different levels of sub-directory?
For example, can I include all .txt files that are in the first level of sub-directory only, and ignore any others?
If using regex it would look like this:
Include: /[^/]*/*.txt
And it would:
/dir/include.txt
/dir2/include.txt
/dir3/include.txt
/dir/subdir/exclude.txt
/dir/subdir/subdir/subdir/exclude.txt
Thanks!
Include or exclude files based on sub-directory depth
- Posts: 5
- Joined: 14 Jul 2021
- Posts: 5
- Joined: 14 Jul 2021
I found the answer:
Include: /*/*.txt
Exclude: /*/*/*.txt
It's a bit cumbersome however. Is there / can we get / a syntax for /*/ where it's only one folder, and /**/ where it's multiple (or however the syntax should work)?
Or even better, add regex support! :D
Include: /*/*.txt
Exclude: /*/*/*.txt
It's a bit cumbersome however. Is there / can we get / a syntax for /*/ where it's only one folder, and /**/ where it's multiple (or however the syntax should work)?
Or even better, add regex support! :D
- Posts: 2450
- Joined: 22 Aug 2012
Modifying an existing, established convention is generally a bad idea, because it may affect the behavior of existing saved syncs. Then better use a "new"/different wildcard character (than *) that is less eager.
As communicated before, also I would love to see regex support in the Include and Exclude Filters.
It may help overcome many of the present limitations, and the need for using multiple left-right pairs (as per the 1st example).
However, even more than a single "new" wildcard character, it creates the need for escaping regex characters that may also be part of existing file- or folder-names (or vice-versa). And unfortunately the standard regex escape character, the backslash (\), is already used in the existing Filter definitions ...
The most feasible option then would be to give the user the option to choose between either the existing Filter definitions or regex based ones. In the regex based ones always use a forward slash (/) as a folder separator (also in a Windows environment), use the backslash (\) as the regex escape character, and live with the fact that characters that have a special meaning in regex need to be escaped when used in normal file or folder definitions.
But at least as relevant: it would require the FFS author to develop and maintain two separate Filter definition approaches.
As communicated before, also I would love to see regex support in the Include and Exclude Filters.
It may help overcome many of the present limitations, and the need for using multiple left-right pairs (as per the 1st example).
However, even more than a single "new" wildcard character, it creates the need for escaping regex characters that may also be part of existing file- or folder-names (or vice-versa). And unfortunately the standard regex escape character, the backslash (\), is already used in the existing Filter definitions ...
The most feasible option then would be to give the user the option to choose between either the existing Filter definitions or regex based ones. In the regex based ones always use a forward slash (/) as a folder separator (also in a Windows environment), use the backslash (\) as the regex escape character, and live with the fact that characters that have a special meaning in regex need to be escaped when used in normal file or folder definitions.
But at least as relevant: it would require the FFS author to develop and maintain two separate Filter definition approaches.
- Posts: 5
- Joined: 14 Jul 2021
** is the standard in many glob implementations (and glob-like shells) so would be the logical thing to use I'd think.
* matches anything in the current directory.
** matches anything in all directories.
However most software that I use supports the use of regex for file and file path matching, and it's fine. As far as I can tell no one is having issues with having to escape everything :)
While I use FreeFileSync and it's great software, unfortunately the limited include/exclude filtering has made it impossible for me to use for anything complex.
My recommendation would be to simply add a flag that allows the insertion of regex. Still support the existing glob-like syntax, but add regex as well. It's confusing but at least it's very full-featured then.
For example, here's something seemingly simple that it seems I cannot do:
I want to copy all the files in the root level of a directory, but not all the files in most sub-directories, however I do want to copy only *some* of the sub-directories (including all the files within them).
I cannot work out any way to do that. It seems impossible.
* matches anything in the current directory.
** matches anything in all directories.
However most software that I use supports the use of regex for file and file path matching, and it's fine. As far as I can tell no one is having issues with having to escape everything :)
While I use FreeFileSync and it's great software, unfortunately the limited include/exclude filtering has made it impossible for me to use for anything complex.
My recommendation would be to simply add a flag that allows the insertion of regex. Still support the existing glob-like syntax, but add regex as well. It's confusing but at least it's very full-featured then.
For example, here's something seemingly simple that it seems I cannot do:
I want to copy all the files in the root level of a directory, but not all the files in most sub-directories, however I do want to copy only *some* of the sub-directories (including all the files within them).
I cannot work out any way to do that. It seems impossible.
- Posts: 2450
- Joined: 22 Aug 2012
> I cannot work out any way to do that. It seems impossible.
The "trick" in the present FFS setup is as per the above cited 1st example: use multiple, possibly identical left-right pairs with local Include and/or Exclude Filter settings. E.g.
Use two identical left-right base folder pairs.
For the 1st pair use a local Include Filter * and a local Exclude Filter adding \*\* (or /*/* )
For the 2nd pair use a local Include Filter that lists the *some* subdirectories and a local Exclude Filter without additions OR (if more convenient) use a local Include Filter * and a local Exclude Filter that excludes all subdirectories except those *some* to be included.
Alternatively, you can create a 1st left-right pair as described, and add a further left-right pair for each of the *some* directories to be included.
Initially this approach seems cumbersome, but once you get the hang of it, it is actually quite straight-forward.
The "trick" in the present FFS setup is as per the above cited 1st example: use multiple, possibly identical left-right pairs with local Include and/or Exclude Filter settings. E.g.
Use two identical left-right base folder pairs.
For the 1st pair use a local Include Filter * and a local Exclude Filter adding \*\* (or /*/* )
For the 2nd pair use a local Include Filter that lists the *some* subdirectories and a local Exclude Filter without additions OR (if more convenient) use a local Include Filter * and a local Exclude Filter that excludes all subdirectories except those *some* to be included.
Alternatively, you can create a 1st left-right pair as described, and add a further left-right pair for each of the *some* directories to be included.
Initially this approach seems cumbersome, but once you get the hang of it, it is actually quite straight-forward.
- Posts: 5
- Joined: 14 Jul 2021
I guess the software is designed for simpler use-cases than what I'm wanting.
The multiple pair method would result in me having an absurd number of pairs.
I probably need to look into other solutions.
I do like FreeFileSync for simpler things though - I use it to compare folders :)
The multiple pair method would result in me having an absurd number of pairs.
I probably need to look into other solutions.
I do like FreeFileSync for simpler things though - I use it to compare folders :)
- Posts: 2450
- Joined: 22 Aug 2012
Well, perhaps "unfortunately", the FFS author has chosen to use another, possibly even more common standard (as e.g. in Windows) in which the wildcard * is fully eager (including directory separators).** is the standard in many glob implementations (and glob-like shells) so would be the logical thing to use I'd think. ...ned, 14 Jul 2021, 10:41
That's the problem with standards: there are so many to choose from ...
But as I wrote, within FFS the eager * is already for years an established convention, and modifying it may affect the behavior of existing saved FFS syncs. And therefore, in my view, do not find it the logical thing to suddenly use ** in FFS instead.
- Posts: 2450
- Joined: 22 Aug 2012
> The multiple pair method would result in me having an absurd number of pairs.
I also described the option of using just two pairs and local Include or Exclude Filters ...
But obviously you always need to describe in one way or another the subdirectories to be included, or conversely those to be excluded, whichever is more convenient. FFS even allows you to do so via the GUI.
And obviously when regex would be available you also need to specify which subdirectories to include or, conversely, to exclude.
I also described the option of using just two pairs and local Include or Exclude Filters ...
But obviously you always need to describe in one way or another the subdirectories to be included, or conversely those to be excluded, whichever is more convenient. FFS even allows you to do so via the GUI.
And obviously when regex would be available you also need to specify which subdirectories to include or, conversely, to exclude.
- Posts: 4056
- Joined: 11 Jun 2019
Please, no Regex... Windows uses the same that FFS uses, way less confusing
- Posts: 5
- Joined: 14 Jul 2021
I keep finding relatively simple scenarios which don't seem to be possible without the use of multiple pairs (and which would of course all be solved by allowing regex). If you think you can do it without using multiple pairs, how would I do this?
Exclude all files in subdirectories AND include several specific subdirectories and most of the files within them
Or to phrase the same thing another way:
Exclude all files in subdirectories EXCEPT for several specific subdirectories BUT still exclude some files within them
Exclude all files in subdirectories AND include several specific subdirectories and most of the files within them
Or to phrase the same thing another way:
Exclude all files in subdirectories EXCEPT for several specific subdirectories BUT still exclude some files within them