你好大感谢mjolinor这个真正快速有效的代码。此代码在每个文件的末尾添加了第5列和第6列(带有Header5和Header6)。现在我想做“小?”更改为此代码并在Header1之前添加这两列。(在第一列中将是文件的名称,第二列始终为0,然后是其余数据)。 希望只需要进行一些小改动,因为我真的很喜欢Mjolinor代码的工作速度(我在一个目录中有大约3000个文件)。
$InputFolder = 'c:\SomeFolder'
$OutputFolder = 'c:\SomeOtherFolder'
Get-ChildItem $InputFolder -Filter *.* |
where {-not $_.psiscontainer} |
foreach {
$FileName = $_.Name
$BaseName = $_.Basename
$data = Get-Content $_ -ReadCount 0
"$($data[0]),Header5,Header6" | Set-Content $OutputFolder\$FileName
$data[1..($data.Length -1)] -replace '$',",0,$BaseName" |
Add-Content $OutputFolder\$FileName
}
答案 0 :(得分:0)
试试这个:
$InputFolder = 'c:\SomeFolder'
$OutputFolder = 'c:\SomeOtherFolder'
Get-ChildItem $InputFolder -Filter *.* |
where {-not $_.psiscontainer} |
foreach {
$FileName = $_.Name
$BaseName = $_.Basename
$data = Get-Content $_ -ReadCount 0
"Header6,Header5,$($data[0])" | Set-Content $OutputFolder\$FileName
$data[1..($data.Length -1)] -replace '^',"$BaseName,0," |
Add-Content $OutputFolder\$FileName
}