12. September 2015 23:40
function NAVTransFileObjIndex
{
param (
[parameter(Mandatory=$true)]
[string] $NAVTranslationFile)
$WorkingFolder = "$env:temp\OBJINDEX"
if (-not(test-path $WorkingFolder)) {New-Item -path $WorkingFolder -ItemType directory -force}
Remove-Item -path $WorkingFolder\*.* -recurse
foreach ($line in [System.IO.File]::ReadLines($NAVTranslationFile))
{
$PosDash = $line.IndexOf("-")
$RawObjectID = $line.Substring(0,$posDash)
if ($RawObjectID -ne $OldObjectID)
{
$ObjectTypeOneChar = $line.Substring(0,1)
$ObjectID = $line.Substring(1,$posDash-1)
Switch ($ObjectTypeOneChar)
{
"T" {$CurrFileName = "TAB$ObjectID.TXT"}
"N" {$CurrFileName = "PAG$ObjectID.TXT"}
"R" {$CurrFileName = "REP$ObjectID.TXT"}
"C" {$CurrFileName = "COD$ObjectID.TXT"}
"X" {$CurrFileName = "XML$ObjectID.TXT"}
"M" {$CurrFileName = "MEN$ObjectID.TXT"}
"Q" {$CurrFileName = "QUE$ObjectID.TXT"}
"F" {Throw "Object type code $ObjectTypeOneChar for Form not allowed."}
"D" {Throw "Object type code $ObjectTypeOneChar for Dataport not allowed."}
default {Throw "Object type code $ObjectTypeOneChar not recognized. Add this new type in the Switch statement in the script."}
}
if (-not(test-path "$WorkingFolder\$CurrFileName"))
{
New-Item -path "$WorkingFolder\$CurrFileName" -ItemType file -force
$OldObjectID = $RawObjectID
}
}
}
}