$FileIn = 'C:\Temp\test.txt'
if (!(Test-Path $FileIn))
{
Write-Error "ERROR: Input file `"$FileIn`" does not exist."
return
}
$path = split-path -parent $FileIn
$header = Get-Content $FileIn | ? { $_ } | select -First 2
Get-Content $FileIn | ? { $_ } | Select -Skip 2 |
% {
$line = $_ -replace "0:00:00", " "
$FileOut= $path + $line.SubString(20,50).Trim() + '.txt'
if (!(Test-Path $FileOut)) { $line = "$header`r`n$line" }
$line | Out-File -Append $FileOut
}
This also resolves the issue with '-------' and the added plus in the file names. (I hate PowerShell trying to do smart things with strings while I don't want it to.)
Anyway, I would use a PS script here. You should have insisted on one in your prior question ;-).
This should do the same as the VBS code, it is using almost the same logic:
Open in new window