Reputation: 503
I'm looking for a PowerShell version of the following Linux command for CI with GitHub actions:
find . -name "*.py" -not -path "./exclude_dir/*" | xargs pylint
here is where I'm now:
get-childitem -path $pwd -include *.py -recurse -name
at the moment I have no idea how to exclude "exclude_dir" and apply pylint
to the selected python files.
Any help would be very appreciated!
Thanks in advance!
Best, Alexey
Upvotes: 0
Views: 345
Reputation: 439058
While Get-ChildItem
does have an -Exclude
parameter, it only operates on the file-name part, not on the full path.
Therefore, you must perform the exclusion filtering after the fact, using the negated form of -like
, the wildcard matching operator
pylint ((Get-ChildItem -Recurse -Name -Filter *.py) -notlike 'exclude_dir/*')
Note the use of -Filter
rather than -Include
, which speeds up the operation, because filtering happens at the source rather than being applied by PowerShell after the fact.
However, given that you're seemingly only excluding a single top-level folder, you could try:
pylint (Get-ChildItem -Recurse -Path * -Filter *.py -Exclude exclude_dir)
Note that I've omitted -Name
in this case, because it wouldn't work properly in this scenario. As a result, the matching files are implicitly passed as full paths to pylint
.
As of PowerShell 7.0, -Name
exhibits several problematic behaviors, which are summarized in this answer.
Upvotes: 1