我創建了一個使用 PowerShell 壓縮超過 N 天的檔案的腳本。像這樣:
param (
$dirPath, `
[int] $daysAgo, `
$logOutput=$dirPath "\old_reports.log", `
$fileExt
)
$curDate = Get-Date
$timeAgo = ($curDate).AddDays($daysAgo)
$files = Get-ChildItem -Recurse `
-Path $dirPath `
-Include *.$fileExt| `
Where-Object { $_.LastWriteTime -lt $timeAgo } | `
Select -ExpandProperty FullName
& 'C:\Program Files\7-Zip\7Z.exe' a -t7z -mx9 old_reports.7z $files -bb1 -sdel
echo $files > $logOutput
它正在作業,但是,由于檔案很多,填充$files變數需要一段時間。在執行此操作時,提示僅顯示閃爍的游標。因此,我不知道腳本是否真的在做某事,或者它被意外點擊暫停了。
有沒有辦法表明$files變數正在接收輸入?
uj5u.com熱心網友回復:
如果不重組您的命令 - 從而犧牲性能 - 我只看到一個選項:
除了在 variable 中捕獲檔案資訊物件之外,$files還可以將它們列印到顯示幕上,這可以在common-OutVariable引數的幫助下完成:
# Output the files of interest *and* capture them in
# variable $files, via -OutVariable
Get-ChildItem -Recurse `
-Path $dirPath `
-Include *.$fileExt| `
Where-Object { $_.LastWriteTime -lt $timeAgo } | `
Select -ExpandProperty FullName -OutVariable files
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/472116.html
上一篇:從另一個變數中提取變數中的值
