Last active
May 1, 2019 17:45
-
-
Save cwg999/d6cabce5004623be7ffc00f5840ebb17 to your computer and use it in GitHub Desktop.
Get Number of PDF Pages (Greater than 1) Parallel with Throttle Limit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ArrayList = [System.Collections.ArrayList]@() | |
# Note: this scripts searches for folders named "Single" recursively from the starting folder. | |
Get-ChildItem -Path .\ -Recurse | Where-Object { | |
$_ -is [System.IO.FileInfo] ` | |
-and ($_.Directory.Name -eq 'Single') | |
} | ForEach-Object { | |
$ArrayList.add($_.FullName) | |
} | |
# Threaded task to use pdfk to get files. | |
workflow Test-Workflow{ | |
param( | |
[Parameter (Mandatory = $true)] | |
[System.Collections.ArrayList]$ArrayList | |
) | |
# Multithreaded - that was easy. | |
ForEach -Parallel -throttlelimit 5 ($file in $ArrayList) | |
{ | |
$command = '"E:\Program Files (x86)\PDFtk Server\bin\pdftk.exe" "'+$file+'" dump_data | findstr NumberOfPages' | |
$output = iex "& $command" | |
$pages = $output.Substring(15,$output.length-15) | |
# Only output files with more than one page. (These files were supposed to be "single" page pdfs) | |
if($pages -gt 1){ | |
Write-Output $file $pages | |
} | |
# Write-Output $output | |
} | |
} | |
Test-Workflow -ArrayList ($ArrayList) | |
Write-Host "Press any key to continue ..." | |
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | |
Write-Host "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment