Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm writing a program and part of it involves reading from files in certain folders in order to combine them into single files. The top level folder is C:\\PROGRAMS\\.

So for example one folder in this directory would generally look something like:
C:\\PROGRAMS\\AAA-999a
which contains the files...
\\AAA-999a_Test1.txt
\\AAA-999a_Test2.txt

These two .txt files are combined into a single .txt file in the same folder, AAA-999a.txt.

I already have the code that does this if the user gives the string that matches the folder name; in this case AAA-999a.

However, the PROGRAMS\\ directory contains many of these folders and I want to be able to make a call that runs through every folder in the directory beginning with AAA, BBB or CCC and uses the code I described above on them (folders can be added or removed any time, and can have a different -999a part of their name, but will always begin with AAA, BBB or CCC).

I guess my problem is I don't really know where to start. Any code, pseudocode, or just an idea of how to get started on this would be great.

Thanks!

EDIT:
I should add that these files are combined with a file in the top level directory named Common.txt. Common.txt has flags in its code that are used to determine when to start reading the test files. So the first part of Common.txt is read until it finds //--Test1 Start--// then reads in the Test1 file. It will then continue reading from Common.txt until //--Test2 Start--// is found. Then the rest of Common.txt is read in.
Posted
Updated 24-Jun-11 5:01am
v2

If the order that the files are concatenated together matters, you will likely need to create a map of some sort in a pre-scan of the folders in question. That map could contain a list of the file paths in the order that you wish to stitch them together. At that point you simply need to iterate through the list of paths in order and perform the concatenation to your output file.
 
Share this answer
 
Comments
obp42 24-Jun-11 11:03am    
Thanks Marcus, any advice on how to do this pre-scan? If I got that list I could just call the code I already have written for each folder.
Take a look at the sample here. This one does recursive search of the directory in VC++. You will have to change the code very little to get it working for your app logic

How to recursively search folders by using Visual C++[^]
 
Share this answer
 
Comments
obp42 24-Jun-11 11:38am    
Skimmed over this a little bit and I like what I've seen, I think I can definitely modify it to work with my code. I'll give it a try and get back to you
obp42 24-Jun-11 15:07pm    
After playing around with it a little bit, it looks like this is going to work. Very helpful link, thanks Vivek
You can start by looking at FindFirstFile[^] or FindFirstFileEx[^] functions. Both allow you to find a file/subfolder by mask, but the second allows you to specify additional attributes (in your case, look for directories only)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900