Merging CSV files and appending (Never exits Loop)

Hi,

Can anyone tell me why when I run this script why it never stops it just continually loops through the folder? Or at least that is what it seems to be doing since it produces a gigantic file when I should be getting at most a 1 or 2 MB csv file based on my test case. All .csv files have the same headers.

What is should be doing:

  1. Get the all .csv files in a folder
  2. Loops through for each csv files
    1. imports .csv file
    2. Exports and appends data to the Output file
  3. Exits after all files are complete. (This seems to be where it fails since it never seems to exit the loop.)

$OutputFile = 'file.csv' $Folder = 'folderlocation' Get-ChildItem -Path $Folder -Filter *.csv | ForEach-Object { Import-Csv -LiteralPath $_.FullName | Export-Csv -Append -LiteralPath $OutputFile -NoTypeInformation} 

Like it works it kind of works if you manually stop it after like 2 seconds of running. But ultimately I want to allow users and attach it to a GUI so end users can have a easy way on our intranet site to combine .csv files.

submitted by /u/Josh02001
[link] [comments]

Leave a Reply