drop last line of each file processed
there way i;m processing files can drop last line of each file before write it? last record in each of files process total record
don't want include in final file. script process thru multiple folders , rolls data single file. need drop
last record before appending file. sistem.csv single file created. last record in each of files has record starting
$z or $z. have parm file pass script has path , shortname.
d:\areasistemi1\folder1~e10
d:\areasistemi1\folder2~e13
*.spx files in folder1 , folder2 this:
e200,%s001,&d000
e200,%s001,&d000
e200,%s001,&d000
$z,0,9,0
before write sistem.csv want not write last record in each of files.
param ( [string]$path ) $myfiles = import-csv -delimiter '~' -path $path -header path, shortname # can call $myfiles.path #returns path $myfiles.shortname # returns 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 $date" >> $path\sistem.log $newname=($_.fullname -replace ".spx",$date) $file = [system.io.path]::getfilenamewithoutextension($_.fullname) "file backup name $newname" >> $myfile.pathsistem.log rename-item $_.fullname $newname "renamed file $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 $newname " >> $path\sistem.log } } # .\newload.ps1 c:\areasistemi1\areasistemi.txt >> runlog.txtthanks.
sorry typo error. pls try below one
foreach ($line in $lines[0..($lines.length -2)])
rgds,
Windows Server > Windows PowerShell
Comments
Post a Comment