powershell - 您可以在运行 Get-ChildItem 以编译文件夹大小列表时写入过滤器以排除某些文件夹吗?
问题描述
我需要在一个目录中获取一组子文件夹的 csv 文件,该文件标记每个文件夹及其大小(最好以 GB 为单位)。
到目前为止,我有这个:
$targetPath = '\\folderpath\users'
(Get-ChildItem $targetPath -Recurse | Measure-Object Length -Sum).Sum
目录中的每个子文件夹中都有一个文件夹,我没有权限/访问权限,因此每次运行脚本时,都会收到拒绝访问错误。
文件夹路径如下所示:
'\\folderPath\users\.V6'
是否可以为上述文件夹写入排除项,并在收集用户文件中每个文件夹的大小时让脚本跳过它?文件夹的大小很小,因此不会对结果产生影响。
解决方案
Get-ChildItem 具有 -Include 和 -Exclude 参数。
-Exclude <String[]> 以字符串数组的形式指定此 cmdlet 在操作中排除的一个或多个项目。此参数的值限定了 Path 参数。输入路径元素或模式,例如 *.txt。允许使用通配符。
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Get-ChildItem).Parameters
(Get-Command -Name Get-ChildItem).Parameters.Keys
Get-help -Name Get-ChildItem -Examples
# Results
<#
Get-ChildItem
Get-Childitem -System -File -Recurse
Get-ChildItem -Attributes !Directory,!Directory+Hidden
dir -att !d,!d+h
dir -ad
Get-ChildItem -File -Attributes !ReadOnly -path C:\ps-test
get-childitem . -include *.txt -recurse -force
get-childitem c:\windows\logs\* -include *.txt -exclude A*
get-childitem -name
#>
Get-help -Name Get-ChildItem -Full
Get-help -Name Get-ChildItem -Online
推荐阅读
- php - Wordpress:如何从其他帖子类型访问字段?无 ACF
- javascript - 按需生成静态站点
- android - Hashmap 到 Recycler 视图 Android
- javascript - 如何在 ES6/React 的段落中显示来自 2 个数组的值
- database - oracle sqlplus 在整整一个小时后返回调用程序而没有任何结果
- angular - Angular pipe - Angular Mat-Table - 如何修改管道以正确呈现数据?
- html - 为什么在缩放(1.5)效果后光标悬停时我的图像会被截断?
- reactjs - 如何在 React js 中下载一种流文件?
- python - numpy.savetxt 将数组保存在单个单元格中?
- apache-spark - 为什么删除或选择列在 Spark Structured Streaming 中无法正常工作?