![]() |
Merge csv file from many folders
I retrieve data from a cash register on a daily base. The data are saved as
follows: C:\dd_mm_yyyy\hh_mm\plu.csv every day a different folder and subfolder is created with different date (main folder) and different time(subfolder). in the .csv file is not stored the date. What i have to do: tell excel to go to the main folder get the date go to the subfolder and get the file plu.csv and copy few data and return them in an excel LIST copy the data say in col B and put the date in column A and copy through the end of the list. second step back to the main folder (the one of the day after) and do the same loop untill all the date are retrieved. PS csv file are closed. i looked at ron debruin web site but i was not able to get a solution Thanks Andrea |
Merge csv file from many folders
try this code
Sub getcashregfiles() datestring = Format(Now(), "dd_mm_yyyy") Set fso = CreateObject _ ("Scripting.FileSystemObject") Set folder = _ fso.GetFolder("C:\temp\" & datestring) If folder.subfolders.Count 0 Then For Each sf In folder.subfolders Set fso1 = CreateObject _ ("Scripting.FileSystemObject") Set folder1 = _ fso1.GetFolder(sf) If folder1.Files.Count 0 Then For Each file In folder1.Files 'add code to open each file here. Next file End If Next sf End If End Sub "Andrea" wrote: I retrieve data from a cash register on a daily base. The data are saved as follows: C:\dd_mm_yyyy\hh_mm\plu.csv every day a different folder and subfolder is created with different date (main folder) and different time(subfolder). in the .csv file is not stored the date. What i have to do: tell excel to go to the main folder get the date go to the subfolder and get the file plu.csv and copy few data and return them in an excel LIST copy the data say in col B and put the date in column A and copy through the end of the list. second step back to the main folder (the one of the day after) and do the same loop untill all the date are retrieved. PS csv file are closed. i looked at ron debruin web site but i was not able to get a solution Thanks Andrea |
Merge csv file from many folders
hi Joel,
i tried but it said path not found. of course i substituted your path with the right one thanks anyway andrea "Joel" wrote: try this code Sub getcashregfiles() datestring = Format(Now(), "dd_mm_yyyy") Set fso = CreateObject _ ("Scripting.FileSystemObject") Set folder = _ fso.GetFolder("C:\temp\" & datestring) If folder.subfolders.Count 0 Then For Each sf In folder.subfolders Set fso1 = CreateObject _ ("Scripting.FileSystemObject") Set folder1 = _ fso1.GetFolder(sf) If folder1.Files.Count 0 Then For Each file In folder1.Files 'add code to open each file here. Next file End If Next sf End If End Sub "Andrea" wrote: I retrieve data from a cash register on a daily base. The data are saved as follows: C:\dd_mm_yyyy\hh_mm\plu.csv every day a different folder and subfolder is created with different date (main folder) and different time(subfolder). in the .csv file is not stored the date. What i have to do: tell excel to go to the main folder get the date go to the subfolder and get the file plu.csv and copy few data and return them in an excel LIST copy the data say in col B and put the date in column A and copy through the end of the list. second step back to the main folder (the one of the day after) and do the same loop untill all the date are retrieved. PS csv file are closed. i looked at ron debruin web site but i was not able to get a solution Thanks Andrea |
All times are GMT +1. The time now is 05:48 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com