![](/img/trans.png)
[英]How do I get the number of distinct files in a directory in powershell?
[英]How can I monitor the number of incoming and processed files in a directory with PowerShell?
我有此PowerShell腳本,用於監視目錄中存在的文件數。 這里是:
#sleep in seconds
$SleepTimeOut = 300
#start looping here
Do{
$path = 'TargetDirectory'
$stats = 0
$files = @(Get-ChildItem -Path $path -Filter '*.ZIP')
if ($files -ne $null) {
$stats = $files.Count
} else {
$msg = 'Message: No files'
Write-Output $msg
}
Get-Date | Out-File -Append 'C:\Monitoring\Logs.csv'
Write-Output "Count: $stats files" | Out-File -Append 'C:\Monitoring\Logs.csv'
Write-Output ".. Files COUNT in Progress...Please Don't Close ..`n"
sleep $SleepTimeOut
}
while ($Exit -ne $True)
它將結果附加到CSV文件。 我只想知道是否有一種方法可以在腳本的5分鍾睡眠時間內監視傳入和處理的文件。 任何幫助將不勝感激。
如BenH所述,您可以嘗試將事件與IO.FileSystemWather
一起IO.FileSystemWather
。 如果該選項不適合您,則另一個選擇是將GetChildItem
用於要監視的文件夾,並檢查每個文件中的LastWriteTime。 從上次循環運行開始進行比較檢查,並記錄任何新文件或更新文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.