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

chilly_bang

Board Regular
Joined
Jun 17, 2016
Messages
56
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

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,499
try Power Query (Get&Transform) with From Folder feature
 

Watch MrExcel Video

Forum statistics

Threads
1,133,244
Messages
5,657,582
Members
418,401
Latest member
B_A_M155

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