0

Been trying variations of this and this, but I think what's tripping things up is the fact that they're all named the same and all the examples I've seen specify wildcards (*.csv) for copy or Get-ChildItem | Import-Csv.

Sources:

C:\foo\bar\list.csv

c:\foo\foobar\list.csv

c:\foo\foobarfoo\list.csv

...

Destination: c:\foo\merged.csv

Help a tired old brother out.

gravyface
  • 889
  • 2
  • 12
  • 26

1 Answers1

0
$getFirstLine = $true

get-childItem "c:\path\to\files\*.csv" | foreach {
$filePath = $_

$lines = Get-Content $filePath  
$linesToWrite = switch($getFirstLine) {
       $true  {$lines}
       $false {$lines | Select -Skip 1}

}

$getFirstLine = $false
Add-Content "c:\path\to\files\final.csv" $linesToWrite
}

https://code.adonline.id.au/merge-multiple-csvs-with-powershell/

gravyface
  • 889
  • 2
  • 12
  • 26