Is there a way as i;m processing files can I drop the last line of each file before I write it? The last record in each of files I process is a total record
which I don't want to include in my final file. The script process thru multiple folders and rolls all the data to a single file. I just need to drop
the last record before appending to my file. sistem.csv is the single file created. The last record in each of the files always has a record starting
with $z or $Z. I have a parm file that I pass to script that has PATH and a shortname.
D:\AreaSistemi1\folder1~e10
D:\AreaSistemi1\folder2~e13
*.spx files in folder1 and folder2 look like this:
E200,%s001,&d000
E200,%s001,&d000
E200,%s001,&d000
$z,0,9,0
Before I write is to sistem.csv I want to not write the last record in each of the files.
param ( [string]$path ) $myFiles = Import-Csv -Delimiter '~' -Path $path -Header Path, ShortName # Then you can call it like so $myFiles.Path #Returns just the path $myFiles.ShortName # Returns the shortname $path='D:\AreaSistemi1\' foreach ($myFile in $myFiles) { get-childitem -path $myFile.Path *.spx | % {" Starting File Process....." >> $myFile.Pathsistem.log $PDate = get-date $date = get-date -uformat "_%d_%m_%Y_%H%M%S.bak" #"Set backup date to $date" >> $path\sistem.log $newname=($_.fullname -replace ".spx",$date) $file = [System.IO.Path]::GetFileNameWithoutExtension($_.fullname)"File backup name is $newname" >> $myFile.Pathsistem.log Rename-Item $_.fullname $newname"Renamed file to $newname" >> $myFile.Pathsistem.log $lines = get-content $newname foreach ($line in $lines) { $line + " " + $myFile.ShortName | Out-File "$path\sistem.csv" -append } Write-Host $_.fullname "Files Processed on $PDate are $newname " >> $path\sistem.log } } # .\newload.ps1 c:\AreaSistemi1\AreaSistemi.txt >> Runlog.txtThanks.