Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to exclude multiple files/directories from a folder #292

Closed
BernH4 opened this issue Nov 18, 2021 · 5 comments
Closed

How to exclude multiple files/directories from a folder #292

BernH4 opened this issue Nov 18, 2021 · 5 comments

Comments

@BernH4
Copy link

BernH4 commented Nov 18, 2021

I tried the following:

- link:
  ~/test/:
  path: test/*
  exclude: [first.txt, second.txt] 

But it keeps adding everything in the directory.

I also tried:

exclude: 
  - first.txt
  - second.txt

Its probably some basic thing but i cant figure it out, thanks.

@anishathalye
Copy link
Owner

Sorry for the confusing UI/UX here. The exclude paths are globs themselves, and we test if the glob expansion from the path matches the glob in the exclude. So in this case, we are checking if the glob first.txt matches test/first.txt, which it does not. If you put test/first.txt and test/second.txt as the two exclude files, i.e.:

- link:
    ~/test/:
      path: test/*
      exclude: [test/first.txt, test/second.txt]
      glob: true

Then it should work.

I think this is confusing; intuitively, you might expect the exclude patterns to match against the * from the glob, not the entire glob? In any case, this should be clarified in the README, and perhaps we can consider changing the behavior here as well.

Hope this solves your immediate problem, and would appreciate hearing any thoughts you have on this matter.

@BernH4
Copy link
Author

BernH4 commented Nov 19, 2021

you might expect the exclude patterns to match against the * from the glob, not the entire glob?

Yes, thats how i thought it would behave and in I think that would be better than the current solution.
I don't see any disadvantage changing that but Im not sure if i understand completely how it works.

The solution you gave me works, but i still have problems excluding directories.

- link:
    ~/test/:
      path: test/*
      exclude: [test/not_wanted_dir]
      glob: true

Gives me the error:

No wildcard in glob, directory use undefined: ~/test/ -> ['test/some_other_file_in_test_dir]
Did you want to link the directory or into it?

Adding a trailing slash to the dir:
exclude: [test/not_wanted_dir/]
will ignore the exclude completely, which probably makes sense.

How can I solve this? I thought it would work exactly like files do, by just mentioning their name (without trailing slash).

Also because you asked my about my opinion:
I maybe miss something but why is it necessary to define a specific path again?
If had not read any documentation i would expect to behave like that:

- link:
    ~/test/:
      exclude: [not_wanted_dir, not_wanted_file, dir_inside_test/*.build]

Everthing written inside exclude should be relative to the directory mentioned above (here test/)

While writing this i think i know now the reason, its probably if you dont want to exclude, its if you want to only include files matching a glob right?

@anishathalye
Copy link
Owner

Your first example works, when there are files to include. I think the error message is confusing/wrong in that setting, it should have instead been a warning that there are no files that match that combo of glob + exclude.

If I have this directory structure:

test
├── a
├── b
└── not_wanted_dir
    └── foo

And this config:

- link:
    ~/test:
      path: test/*
      exclude: [test/not_wanted_dir]
      glob: true

I get the intended results, with a and b being linked, but not the directory.

You don't need to specify things like dir_inside_test/*.build, because the glob/link is not recursive.

@BernH4
Copy link
Author

BernH4 commented Dec 12, 2021

Thanks for your help, got it working :)

anishathalye added a commit that referenced this issue Jul 9, 2023
@anishathalye
Copy link
Owner

Docs added in 9f8fd76. Thanks again for pointing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants