# VQ Add Zero's
# create Renum file add zeros
# ======================================
# V2.0 keuze add/remove/extraction
# V2.1 Len afhankelijk van Action
# V2.2 Toevoeging Ophogen patientnummer
#      verbetering showlist top 5 & last 5 lines
#      tijddoorloop : 1000+ regels per seconde
# V2.3 Codes ff ef voorin file verwijderd door toevoeging -encoding default
#      | Out-file ipv >> ingevoerd
#      Output in 1 variabele gezet
# = = = =  AdJ 2022  = = = = 
#
# input actie Add / Remove / Extraction / Increase ID 
# input startnumber
# input endnumber
# input length number (2.1 afhankelijk van Actie)
# 
# == Init Variabelen
Clear
$startnumber=0
$Endnumber=0 
$len=0
$action="X"
$AddValue=0
$showlist="N"
$header="Old ID, New ID"
$filename=".\PatRenumList.lst"
#
Write-host " "
Write-host "   Add zero's "
Write-host " =============="
Write-host " "
$startnumber = read-host -prompt 'Start number   '
$Endnumber = read-host -prompt 'End number     '
$len = read-host         -prompt 'Length number '
# $currentnumber = $startnumber-1   # Prepare first values
# $Endnumber=$Endnumber-1           # Prepare first values
#
$now = get-date
write-host "start writing file : "$now
# | out-file -Append -width $line $
$header| out-file $filename -Encoding default
# echo "Oud,Nieuw" > .\renum.lst    # Write first line
$currentnumber = $startnumber-1   # Prepare first values
$Endnumber=$Endnumber-1           # Prepare first values
# while not currentnumber -EQ endnumber
do {
#
$currentnumber++                 # $currentnumber = $currentnumber+1
$currentNumberString = $currentNumber.ToString()
$paddedcurrentNumberString = $currentNumberString.PadLeft($len,'0')
$line = $currentNumberstring+","+$paddedcurrentNumberString
$line | out-file -append $filename -Encoding default
} while ($currentNumber -le $Endnumber)
# End While 
#
$now = get-date
write-host "stop writing file :  "$now
#
$showlist = read-host      -prompt 'Show List (Y/N) '
if($showlist -EQ "Y"){
  write-host "  "
  write-host " top 5 / tail 5 "
  get-content $filename -TotalCount 6 
  get-content $filename -Tail 5 
Write-host " "
read-host      -prompt 'Press enter to continue ....  '
}
#  == End Of Script == #