Combine Multiple CSV Files into One in Windows
Combining multiple CSV files into one is a common task when you have data split across several exports, such as monthly sales reports or survey responses. This guide shows you several ways to merge them in Windows, from a quick command-line trick to using Excel’s built-in tools. You’ll end up with a single CSV file containing all your rows, with the header row appearing only once.
What You’ll Need
- Your CSV files stored in one folder (or a list of their full paths).
- Access to Command Prompt (cmd) or PowerShell (both built into Windows).
- Optional: Microsoft Excel or a text editor like Notepad for manual methods.
- All CSV files should have the same column structure (same headers in the same order) for a clean merge.
Step-by-Step
Method 1: Using Command Prompt (Fastest)
- Place all the CSV files you want to combine into a single folder. Name them so they sort in the order you want them to appear in the final file (e.g., file1.csv, file2.csv).
- Open Command Prompt: press Win + R, type
cmd, and press Enter. - Navigate to the folder containing your CSV files. For example, if they’re in
C:\Data\Reports, type:cd C:\Data\Reportsand press Enter. - Type the following command and press Enter:
copy *.csv combined.csv
This copies the contents of all CSV files into a new file calledcombined.csv. - Open
combined.csvin a text editor or Excel. If the header row appears multiple times (once for each original file), you’ll need to remove the duplicates—see the Tips section below for a cleaner method.
Method 2: Using PowerShell (Keeps Only One Header)
- Open PowerShell: press Win + R, type
powershell, and press Enter. - Navigate to your folder: type
cd C:\Data\Reports(adjust the path) and press Enter. - Run the following command, which reads each file and writes all lines except the first (header) line from files after the first one:
Get-ChildItem -Filter *.csv | Select-Object -First 1 | Get-Content | Set-Content combined.csv; Get-ChildItem -Filter *.csv | Select-Object -Skip 1 | ForEach-Object { Get-Content $_ | Select-Object -Skip 1 | Add-Content combined.csv }
This createscombined.csvwith the header from the first file and all data rows from every file. - Check the output file to ensure it looks correct.
Method 3: Using Excel (No Command Line)
- Open a blank workbook in Microsoft Excel.
- Go to the Data tab and click Get Data → From File → From Folder.
- Select the folder containing your CSV files and click OK.
- In the dialog that appears, click Combine → Combine & Load.
- Excel will show a preview. Ensure the “First row contains headers� option is checked, then click OK.
- The combined data appears in a new worksheet. Click File → Save As and choose CSV (Comma delimited) to save it as a single CSV file.
Method 4: Using a Text Editor (Manual)
- Open the first CSV file in Notepad (or any text editor).
- Copy all its content.
- Open a new Notepad file and paste the content.
- Open the second CSV file, copy all content except the first line (the header), and paste it at the end of the new file.
- Repeat for each additional file, always skipping the header line.
- Save the new file with a
.csvextension.
Common Mistakes
- Duplicate headers: Using the simple
copycommand includes the header from every file, which corrupts the data structure. - Mismatched columns: If your CSVs have different column orders or names, merging them blindly will produce misaligned data.
- Encoding issues: CSV files saved with different encodings (e.g., UTF-8 vs. ANSI) may show garbled characters after merging.
- Trailing blank lines: Some editors add an empty line at the end of a file, which can create blank rows in the combined output.
- Forgetting to close the output file: If you try to write to a file that’s already open in Excel, you’ll get an error.
Tips
- Use PowerShell for a clean merge: The PowerShell method automatically strips extra headers, saving you cleanup time.
- Keep a backup: Before merging, copy your original files to a separate folder. If something goes wrong, you can start over.
- Check for commas in data: If your data contains commas, ensure the CSV is properly quoted (fields with commas should be enclosed in double quotes).
- Sort files by name: If order matters, rename your files with leading zeros (e.g., 01, 02, …) so that alphabetical sorting matches your desired sequence.
- Use a dedicated tool: For very large files or frequent merging, consider a free tool like CSV Joiner, but the built-in methods are usually sufficient.
Troubleshooting
- The command says “file not found�: Double-check that you’re in the correct folder using
cdand that the files have a.csvextension (not.csv.txt). - The combined file has garbled characters: This usually indicates an encoding mismatch. Open the original files in Notepad, check the encoding in the “Save As� dialog, and convert all files to the same encoding (preferably UTF-8) before merging.
- Excel shows data in one column: This happens if the file uses a different delimiter (like semicolons). Open the file in Notepad and check the separator. If it’s not a comma, you’ll need to adjust your method or use Excel’s “From Text/CSV� import to specify the delimiter.
- The PowerShell command fails with an error: Make sure you’re running PowerShell as a normal user (not necessarily admin). Also, ensure the path contains no spaces; if it does, enclose the path in quotes in the
cdcommand. - The combined file is empty: Verify that the original files are not empty and that the output file isn’t locked by another program.
Frequently Asked Questions
Can I combine CSV files with different columns?
Technically yes, but the result will have misaligned data. It’s best to standardize the columns first, or use a tool that maps columns by header name.
Will the combined file be too large for Excel?
Yes, Excel has a limit of about 1,048,576 rows per worksheet. If your combined data exceeds that, you’ll need to use a database or a text editor to view it.
How do I combine CSV files without duplicates?
If you mean duplicate rows, you’ll need to use a tool like Excel’s “Remove Duplicates� after merging, or use a script that checks for duplicates.
Can I automate this process?
Yes, you can save the PowerShell command as a .ps1 script and run it whenever needed, or schedule it with Task Scheduler.
What if my CSV files have a header row that I want to keep only once?
Use the PowerShell method provided above, which automatically removes extra headers. Alternatively, in Excel’s Combine feature, it handles headers correctly by default.
Is there a way to combine files without using any commands or Excel?
Yes, you can use a text editor and manually copy-paste, but it’s tedious for many files. A free third-party tool like “CSV Merge� can also do it with a GUI.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.