Created
April 23, 2020 13:12
-
-
Save dylanlangston/c083068c985fa180725d8659f6c440f4 to your computer and use it in GitHub Desktop.
Powershell script to recreate PaperVision Capture .PVCSDOC files
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
# Section prompts for PVCSINFO File | |
$validfile = 0 | |
while ($validfile -eq 0) | |
{ | |
set-variable -name batchfile -value (Read-Host -Prompt 'Type Path of .PVCSINFO file') | |
set-variable -name batchpath -value (Split-Path -Path $(Get-Variable batchfile -ValueOnly) -Parent) | |
set-variable -name batchname -value (Split-Path $(Get-Variable batchpath -ValueOnly) -Leaf) | |
foreach ($line in $batchfile) { | |
$extn = [IO.Path]::GetExtension($line) | |
if ($extn -eq ".PVCSINFO" ) | |
{ | |
set-variable -name validfile -value 1 | |
} else { | |
Write-Host "`nNot a valid PVCSINFO File, try again." | |
} | |
} | |
} | |
# Section Confirms that no .PVCSDOC exists and prompts to rename if it does. | |
if (gci $batchpath *.PVCSDOC){ | |
Write-Host "`nA .PVCSDOC file already exists for the" $batchname "batch." | |
Write-host "Would you like to rename the file that's already there and recreate it? (Default is No)" | |
$Readhost = Read-Host " ( y / n ) " | |
Switch ($ReadHost) | |
{ | |
Y {Write-host "`nRenaming $batchname.PVCSDOC to $batchname.PVCSDOC.old"; Rename-Item -Path "$batchpath\$batchname.PVCSDOC" -NewName "$batchname.PVCSDOC.old"} | |
N {exit} | |
Default {exit} | |
} | |
} | |
# Section Creates New PVCSDOC based on the batches contents. | |
Add-Content -Path "$batchpath\$batchname.PVCSDOC" -Value "<?xml version=`"1.0`" encoding=`"utf-8`"?>" | |
Add-Content -Path "$batchpath\$batchname.PVCSDOC" -Value "<BATCHDOCUMENTS>" | |
Add-Content -Path "$batchpath\$batchname.PVCSDOC" -Value " <DOCUMENTS>" | |
set-variable -name DOCINFOFILES -value (dir -Path "$batchpath\Documents" -Filter *.PVCSDOCINFO -Recurse | %{$_.FullName}) | |
foreach ($file in $DOCINFOFILES) { | |
set-variable -name pagecount -value 0 | |
set-variable -name filename -value ([System.IO.Path]::GetFileNameWithoutExtension($file)) | |
$XPathPages = "/DOCUMENTINFO/PAGES/PAGE" | |
$PAGES = Select-Xml -Path $file -XPath $XPathPages | Select-Object -ExpandProperty Node | |
foreach ($page in $PAGES){ | |
$pagecount = $pagecount+1 | |
} | |
Add-Content -Path "$batchpath\$batchname.PVCSDOC" -Value " <DOC ID=`"$filename`" PP=`"$pagecount`" UB=`"0`" />" | |
} | |
Add-Content -Path "$batchpath\$batchname.PVCSDOC" -Value " </DOCUMENTS>" | |
Add-Content -Path "$batchpath\$batchname.PVCSDOC" -Value "</BATCHDOCUMENTS>" | |
Write-Host "`nA new .PVCSDOC file has been created. Please try and open batch '"$batchname"'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment