Confused with -Include parameter of the Get-ChildItem cmdlet

后端 未结 6 1643

From documentation:

-Include

Retrieves only the specified items. The value of this parameter qualifies the Path parameter. Enter a pa

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 18:15

    Including \* at the end of the path should work around the issue

    PS C:\logfiles> Get-ChildItem .\* -include *.log
    

    This should return .log files from the current working directory (C:\logfiles)

    Alex's example above indicates that a directory with the name foo.log would also be returned. When I tried it, it wasn't but it's 6 years later and that could be from PS updates.

    However, you can use the child item Mode to exclude directories I think.

    PS C:\logfiles> Get-Childitem .\* -include *.log | where-object {$_.mode -notmatch "d"}
    

    This should exclude anything with the 'directory' mode set.

提交回复
热议问题