環境
- Microsoft Windows 10.0.22000.318(21H2)
- PowerShell 7.2.0
準備
PowerShell
# フォルダ「test」を作成
New-Item test -ItemType Directory
# txtファイルを作成
New-Item a.txt -Value a.txtの中身
New-Item b.txt -Value b.txtの中身
# a.txtとb.txtの確認([-Encoding XXX] で文字コードを指定)
Get-Content a.txt, b.txt -Encoding utf8
<#
a.txtの中身
b.txtの中身
#>
New-Itemコマンドのオプション
New-Item
[-Path] <String[]>
[-ItemType <String>]
[-Value <Object>]
[-Force]
[-Credential <PSCredential>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
詳しくはこちら
Get-Contentコマンドのオプション
Get-Content
[-ReadCount <Int64>]
[-TotalCount <Int64>]
[-Tail <Int32>]
[-Path] <String[]>
[-Filter <String>]
[-Include <String[]>]
[-Exclude <String[]>]
[-Force]
[-Credential <PSCredential>]
[-Delimiter <String>]
[-Wait]
[-Raw]
[-Encoding <Encoding>]
[-AsByteStream]
[-Stream <String>]
[<CommonParameters>]
詳しくはこちら
指定したテキストファイルを結合する場合
PowerShell
Get-Content a.txt, b.txt | Set-Content combined.txt
フォルダ内のすべてのテキストファイルを結合する場合
PowerShell
Get-Content *.txt | Set-Content combined.txt
確認
PowerShell
Get-Content combined.txt -Encoding utf8
<#
a.txtの中身
b.txtの中身
#>
参考