1
我想通過一個目錄(按最小文件排序)循環,獲取路徑和文件名,然後將這些結果泵入一個utility.exe程序。PoshRSJob通過文件目錄循環
我試圖做到這一點的多線程與PoshRSJob,但我不甚至看到了應用程序在任務管理器中顯示出來,我得到一個錯誤「null鍵沒有在字面上的哈希不允許的。」對於每個存在的文件(如果50個文件在目錄中,那麼我得到50個錯誤)。我也無法測試節流是否奏效,因爲沒有任何實際運行。
Import-Module C:\PoshRSJob.psm1
Function MultiThread($SourcePath,$DestinationPath,$CommandArg, $MaxThreads){
if($CommandArg -eq "import") {
$fileExt = "txt"
}else{
$fileExt = "ini"
}
$ScriptBlock = {
Param($outfile, $cmdType, $fileExtension)
[pscustomobject] @{
#get the full path
$filepath = $_.fullname
#get file name (minus extension)
$filename = $_.basename
#build output directory
$destinationFile = "$($outfile)\$($filename).$($fileExtension)"
#command to run
$null = .\utility.exe $cmdType -source `"$filepath`" -target `"$destinationFile`"
}
}
#get the object of the passed source directory, and pipe it into start-rsjob
Get-ChildItem $SourcePath | Sort-Object length | Start-RSJob -ScriptBlock $ScriptBlock -ArgumentList $DestinationPath, $CommandArg, $fileExt -Throttle $MaxThreads
Wait-RSJob -ShowProgress | Receive-RSJob
Get-RSJob | Receive-RSJob
}
MultiThread "D:\input" "D:\output" "import" 3
哇,我發誓,我試過了。它的工作原理,謝謝 –
不客氣。查看更新後的答案。更新日誌:修正了(我認爲)'Wait-RSJob'。 :-) –
我也注意到了,並在我看到您的更新評論之前修復了它。再次感謝 –