簡體   English   中英

使用PowerShell合並多個文件夾中的文件

[英]Merge Files over multiple folders using PowerShell

我有如下目錄結構。

根目錄

   Sub_dir1

   Sub_dir2

   ....

在這里,我在根目錄下有多個子文件夾。 現在,每個子文件夾都包含一個message.csv文件。 我想附加它們並創建一個新的csv文件。

假設所有CSV都有相同的列,則應執行以下操作:

$root = 'C:\path\to\Root_dir'
$csv  = 'C:\path\to\output.csv'

Get-ChildItem $root -Filter 'message.csv' -Recurse | % {
  Import-Csv $_.FullName 
} | Export-Csv $csv -NoTypeInformation

要從輸出中刪除重復項,請嘗試以下操作:

$root = 'C:\path\to\Root_dir'
$csv  = 'C:\path\to\output.csv'

Get-ChildItem $root -Filter 'message.csv' -Recurse | % {
  Import-Csv $_.FullName 
} | ConvertTo-Csv -NoTypeInformation | select -Unique | Out-File $csv

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM