Hi all! I'm new in this forum, I got here after hours and hours struggling with a C++ which doesn't work as expected :-)
I have written a little function which checks all the files in a directory and writes their name in a .txt file, the problem is this:
the output only shows the LAST member added(for example the WINDOWS folder) repeted for the -n- number of the folders found( so if 10 files are found instead of showing "file1,file2,ecc.." it shows "WINDOWS,WINDOWS,WINDOWS" etc...
I've already checked and I don't have any problem with the stream itself!
Here is the code,I hope someone will hel me,I'm REALLY getting mad :(
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
void DriveExplore(char* path,char* chosenDir,fstream* theStream)
{
WIN32_FIND_DATA findData;
HANDLE hSearch;
vector<char*,allocator<char*>> folders;
vector<char*,allocator<char*>>::iterator theIterator;
*theStream<<"<r>"<<endl;
*theStream<<chosenDir<<endl;
strcat(path,"\\*");
hSearch=FindFirstFile(path,&findData);
do
{
folders.push_back(findData.cFileName);
}while(FindNextFile(hSearch,&findData));
for(theIterator=folders.begin();theIterator!=folders.end();theIterator++)
{
*theStream<<*theIterator<<endl;
}
}
|
I'm sure the problem is with the vector managing, but I can't understand how to solve :(
Since English is not my first language, I apologize if you don't understand something, in that case I'll try to explain better.
I'm using Visual C++ express 2010