【发布时间】:2015-06-13 14:08:24
【问题描述】:
我在寻找正确的语法时遇到问题,我需要过滤我的结果,仅列出文件数超过指定数量(在我的情况下为 600)的目录。
这是我目前的代码;
$server_dir= "D:\backup"
$export_dir= "C:\support\spcount.txt"
if($server_dir)
{
$folders = Get-ChildItem $server_dir
$output = @()
foreach($folder in $folders)
{
$fname = $folder.Name
$fpath = $folder.FullName
$fcount = Get-ChildItem $fpath | Measure-Object | Select-Object -Expand Count
$obj = New-Object psobject -Property @{FolderName = $fname; FileCount = $fcount} | Format-List;
$output += $obj
}
#Output
$output | Tee-Object -FilePath $export_dir | Format-list FileCount
}
我得到了积极的结果,它列出了备份目录中的所有子项,但是如果目录包含 600 个或更多文件,我需要过滤它以仅显示和输出文本格式。
有人可以帮帮我吗?
我也是相当新的powershell所以如果这个代码不是最好的请拉我,我永远也想学习。
谢谢!
【问题讨论】:
标签: windows shell powershell directory backup