0

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

Alexey Abramov
  • 435
  • 1
  • 3
  • 16
  • Bash [is available](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#using-a-specific-shell) on all platforms (together with all fancy tools), you don't need to stick to PowerShell. – Samira Aug 03 '20 at 11:24
  • Since you've never accepted any answers to your questions (I haven't looked at your other ones), let me give you the standard advice in the next comment. While using Bash may be the solution you went with, future readers may still be interested in a PowerShell solution. – mklement0 Aug 11 '20 at 22:29

1 Answers1

1

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775