Combine multiple CSV and write a part of a folder name as column

chilly_bang

Board Regular
Joined
Jun 17, 2016
Messages
57
I have a folder C:\\data. In this folder are placed time-stamped folders with files, like C:\\d\2020.11.26.16.45.12\data.csv, C:\\d\2020.11.27.16.45.13\data.csv, C:\\d\2020.11.28.16.45.14\data.csv. All files have same names, column headings and column amount.

I want to merge all CSV files from the folder C:\\data and write merged CSV into another folder, like C:\\merged\merged.csv and to add to each portion of the merged data the first 10 characters of the corresponding folder name, so i get the date column.

Example: on merging of the file C:\\d\2020.11.26.16.45.12\data.csv into the first or last column is written 2020.11.26 or, much better, manipulated to 2020-11-26. I will run this script at CMD daily with WIndows Tasks Scheduler.

I've found a solution which works only partly for me: Bulk combine csv files and create column with file name - it doesn't do searching though subfolders and it writes the whole filename into additional column.

Has anyone ideas about a solution, maybe based on the script i cited, or maybe a completely different one?

Thanks on beforehand and kindly greets from Berlin!
 
Last edited:

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,559
Latest member
MrPJ_Harper

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