【问题标题】:Recursively merge identically-named .CSV files into a single file递归地将同名的 .CSV 文件合并到一个文件中
【发布时间】:2020-12-22 02:24:15
【问题描述】:

一直在尝试thisthis 的变体,但我认为问题在于它们的名称都相同,而且我看到的所有示例都为@ 指定了通配符 (*.csv) 987654323@或Get-ChildItem | Import-Csv

来源:

C:\foo\bar\list.csv

c:\foo\foobar\list.csv

c:\foo\foobarfoo\list.csv

...

目的地: c:\foo\merged.csv

帮助一个疲惫的老兄弟。

【问题讨论】:

    标签: csv merge


    【解决方案1】:
    $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/

    【讨论】:

      猜你喜欢
      • 2019-08-28
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-30
      相关资源
      最近更新 更多