Reputation: 563
I have the following directory structure:
root
├─ files
│ ├─ folder1
│ │ ├─ file1.js
│ | └─ file2.js
│ ├─ folder2
│ │ └─ file3.js
│ ├─ file4.js
| └─ file5.js
└─ config.js
How can I match every file inside of file
(and subdirectories) except the files that are in folder1
, in this case file3.js
, file4.js
and file5.js
?
I know I could exclude folder1
with the following: files/!(folder1)/*.js
, but this only matches file3.js
.
Upvotes: 0
Views: 737
Reputation: 637
Try **/files/{*.js,!(folder1)*/*.js}
. You can test using globster.xyz
Upvotes: 1
Reputation: 381
There is probably a more elegant way to do this as I am not too familiar with glob, but I think this will get what you are asking for.
import glob
exclude_pattern = ['folder1']
file_list = glob.glob('./files/**/*', recursive=True)
for pattern in exclude_pattern:
exclude_patternmatch = list(filter(lambda x: pattern in x, file_list))
for item in exclude_patternmatch:
file_list.remove(item)
print(file_list)
output:
['./files/file6.js', './files/file5.js', './files/folder2/file3.js', './files/folder2/file4.js']
Upvotes: 1