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

d0rian

Active Member
Joined
May 30, 2015
Messages
263
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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Watch MrExcel Video

Forum statistics

Threads
1,130,072
Messages
5,639,906
Members
417,118
Latest member
warranty123

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
Top