Directory listing.

Hello,

I've recently gotten a (Windows-only) directory reader together based on MSDN code. I'm trying to adapt it now to handle subdirectories, but it's not going well.

My plan has two phases:
Phase A, get all subdirectories of a specified directory. This works; I end up with a list of subdirectories neatly packed in a vector<string>.

Phase B, for each of the subdirectories, get a list of files in that subdirectory. This does not work; I end up with nonsense characters on my screen.

I'm not sure what the problem is, but I suspect is has to do with my "path making". To find the full path to the subdirectory, I do the following:
1
2
3
4
5
	char fullpath[50];
	strcpy(fullpath, path);
	strcat(fullpath, "/");
	strcat(fullpath, dir.c_str());
	strcat(fullpath, "/");


"path" is a char[] passed to the function and includes the original directory (".//instances"), previously used to get the list of subdirectories. "dir" is a string containing the subdirectory's name.

According to my output ánd the debug Watcher, fullpath contains ".//instances/A/", which is where the first batch of files should be.

The files should be caught using this:
1
2
3
4
5
6
7
8
9
	StringCchLength(fullpath, MAX_PATH, &length_of_arg);
	hFind = FindFirstFile(szDir, &ffd);
		// Add all files to fList
	do {
		if (ffd.dwFileAttributes) {
			fList.push_back(ffd.cFileName);
		}
	} while (FindNextFile(hFind, &ffd) != 0);
	FindClose(hFind);


which is the same way the directories were called (except for the if having an additional variable to see if it's a directory). However, in the end fList only contains a single element, looking like a lot of "Ì" characters.

Anyone who can tell me what I'm doing wrong?
Fixed: Deleted a line too many in the reader apparently...
Topic archived. No new replies allowed.