使用C'组合文件并将文件名附加为csv中的列 [英] Combing a file and appending file name as a column in a csv using C'
问题描述
您好,
我需要添加组合多个csv文件,但添加一个名为Source的标题,该标题将填充文件名。我有一个电源shell脚本,但我已经厌倦了加入我的C#程序。我已经使用了System.Management.Automation并遵循了一些教程,但仍然无法正常工作。我想知道是否有人可以为我写这个,如果我提供了我的powershell skript并添加注释以帮助我将来。
谢谢
cd c:\ pdder
$ files = Get-ChildItem。\| Where-Object {$ _。Extension -eq.csv}
for($ i = 0; $ i -lt $ files.Count; $ i ++){
$ outfile = $ files [$ i] .FullName +out
$ csv = Import-Csv $ files [$ i] .FullName
$ newcsv = @()
foreach($ row in $ csv){
$ row | Add-Member -MemberType NoteProperty -Name'Source'-Value $ files [$ i] .BaseName
$ newcsv + = $ row
}
$ newcsv | Export-Csv $ files [$ i] .Name -NoTypeInformation
}
$ files = Get-ChildItem C:\ folder \ * .csv
$ files | ForEach-Object {Import-Csv $ _} |
Export-Csv -NoTypeInformation C:\ fileder\combined.csv
我尝试过:
我有一个可用的电源shell脚本,但我已经厌倦了添加到我的C#程序。我已经使用了System.Management.Automation并遵循了一些教程但仍然无法正常工作。
files = Get-ChildItem。\| Where-Object {
_。Extension -eq.csv}
for(
i = 0;
Hello,
I need to add combine multiple csv files but adding a header called Source which will be populated with the filename.I have a power shell script that works but Ive tired adding to my C# program. Ive used System.Management.Automation and followed some tutorials but still not working. I was wondering if someone could write it up for me if i provided my powershell skript and add notes to help me in the future.
Thank you
cd c:\folder $files = Get-ChildItem ".\" | Where-Object { $_.Extension -eq ".csv" } for ($i=0; $i -lt $files.Count; $i++) { $outfile = $files[$i].FullName + "out" $csv = Import-Csv $files[$i].FullName $newcsv = @() foreach ( $row in $csv ) { $row | Add-Member -MemberType NoteProperty -Name 'Source' -Value $files[$i].BaseName $newcsv += $row } $newcsv | Export-Csv $files[$i].Name -NoTypeInformation } $files = Get-ChildItem C:\folder\*.csv $files | ForEach-Object {Import-Csv $_} | Export-Csv -NoTypeInformation C:\folder\combined.csv
What I have tried:
I have a power shell script that works but Ive tired adding to my C# program. Ive used System.Management.Automation and followed some tutorials but still not working.
files = Get-ChildItem ".\" | Where-Object {
_.Extension -eq ".csv" } for (
i=0;
这篇关于使用C'组合文件并将文件名附加为csv中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!