简体   繁体   English

Get-Childitem递归,但跳过特定父文件夹中的文件

[英]Get-Childitem Recursive but skip files in particular parent folder

This should be an easy question. 这应该是一个简单的问题。 I need to run Get-Childitem recursively to look for .jpgs in the following folder structure: 我需要递归运行Get-Childitem ,以在以下文件夹结构中查找.jpgs:

'D:\Images\' + $local:YM + '\' + $local:YMD + '\' + $env:USERNAME

The username folder contains jpgs and additional folders containing jpgs. 用户名文件夹包含jpg,其他文件夹包含jpg。 I want the recursive Get-Childitem to address the jpgs in the subfolders of the username folder but skip the jpgs in the username folder itself. 我希望递归的Get-Childitem解决用户名文件夹的子文件夹中的jpg,但跳过用户名文件夹本身中的jpg。

For example I would like the Get-Childitem to address: 例如,我希望Get-Childitem解决:

'D:\Images\2018_03\2018_03_19\Garrett\Shoes\Shoe.jpg'

but not: 但不是:

'D:\Images\2018_03\2018_03_19\Garrett\Shoe.jpg'

I tried using the following path with no success: 我尝试使用以下路径未成功:

'D:\Images\' + $local:YM + '\' + $local:YMD + '\' + $env:USERNAME + '\*\'

I'm not sure if that failed because I didn't state that the wildcard was a directory, if that's the case how do I do that? 我不确定是否失败,因为我没有说明通配符是目录,如果是这种情况,我该怎么做? Any advice or suggestions are welcome. 欢迎任何建议。

Thanks! 谢谢!

Use Where-Object to filter on the DirectoryName property: 使用Where-Object筛选DirectoryName属性:

$DirectoryNameToExclude = 'D:\Images\' + $local:YM + '\' + $local:YMD + '\' + $env:USERNAME
Get-ChildItem . -Recurse |Where-Object {$_.DirectoryName -ne $DirectoryNameToExclude}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM