簡體   English   中英

如何使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM