Powershell - 排除 Get-ChildItem 中的文件夹 [英] Powershell - Exclude folders in Get-ChildItem

查看:53
本文介绍了Powershell - 排除 Get-ChildItem 中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何排除文件夹?现在我对文件夹名称进行了硬编码,但我希望它更灵活.

How to exclude folders ? Now I hardcode the folder names but i want it to be more flexible.

foreach($file in Get-ChildItem $fileDirectory -Exclude folderA,folderb)

推荐答案

"如何排除文件夹?",如果你的意思是所有文件夹:

"How to exclude folders ?" , if you mean all folders :

get-childitem "$fileDirectory\\*" -file 

但它仅适用于 $fileDirectory 的第一级.这递归地工作:

but it works only for the first level of $fileDirectory . This works recursevly :

Get-ChildItem "$fileDirectory\\*"  -Recurse | ForEach-Object { if (!($_.PSIsContainer)) { $_}}

 Get-ChildItem "$fileDirectory\\*"  -Recurse | where { !$_.PSisContainer }

这篇关于Powershell - 排除 Get-ChildItem 中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆