gpt4 book ai didi

Powershell 进度条

转载 作者:行者123 更新时间:2023-12-02 23:15:36 25 4
gpt4 key购买 nike

我是 Powershell 的新手,在获取进度条以使用 foreach-object 循环时遇到问题(如果可能的话)

多亏了克里斯,下面是我到目前为止所拥有的,我的问题是进度条到达一个点,然后出现错误:101 参数大于允许的最大范围 100:

$FolderList = Get-Content C:\Folders.txt
$i = 0

foreach( $Folder in $FolderList )
{

Write-Host $Folder
Get-ChildItem $Folder -Recurse *.pdf | foreach-object{

$fileCount = (Get-ChildItem $Folder).Count
$i += 1
Write-Progress -Activity "Counting Files" -status "Searching...." -percentComplete (($i / $fileCount)*100)

$pdf = c:\pdftk.exe $_.FullName dump_data
$NumberOfPages = [regex]::match($pdf,'NumberOfPages: (\d+)').Groups[1].Value

New-Object PSObject -Property @{
Name = $_.Name
FullName = $_.FullName
NumberOfPages = $NumberOfPages
}
}
}

最佳答案

这是我解决问题的方法:

$i = 0
$pdfFiles = @()

#First, get the files and add them to a collection:
foreach ($folder in $FolderList){
Get-ChildItem $Folder -Recurse *.pdf | %{$pdfFiles += $_}
}

#Measure the collection
$fileCount = ($pdfFiles | Measure-Object).Count

#Do work on the collection
$pdfFiles | foreach-object{
$pdf = c:\pdftk.exe $_.FullName dump_data
$NumberOfPages = [regex]::match($pdf,'NumberOfPages: (\d+)').Groups[1].Value
New-Object PSObject -Property @{
Name = $_.Name
FullName = $_.FullName
NumberOfPages = $NumberOfPages
}
$i += 1
Write-Progress -Activity "Counting Files" -status "Searching...." -percentComplete (($i / $fileCount)*100)
}

关于Powershell 进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com