Concatenate CSV files while also adding filename in a new column?

d0rian

Active Member
Joined
May 30, 2015
Messages
313
Office Version
  1. 365
I have 3 CSV files (each has stock holdings in 3 dif accounts) I download each day, exactly the same format (data in columns A:W), filenames:
- account_1.csv
- account_2.csv
- account_3.csv
I concatenate them all into a single CSV with a simple single-line .bat batch file with this line:
copy C:\Users\user1\Downloads\account*.csv C:\Users\user1\Downloads\concat_file.csv

The problem is that each CSV file contains only raw data, and no indicator as to WHICH account the data comes from so I end up with a single concatenated file of raw data in columns A:W, but no indication as to which rows came from each of the 3 initial CSV files.

So is there anything I can add to the batch file that will make the single concatenated CSV file populate column Y (the first empty column) with the file name of the CSV the rows came from?
(I know there's probably VBA I could write that will run import-from-text functions that can populate column Y with the filename, but I'd prefer doing it via batch file...)
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top