Problem with listing files in a directory

I'm using this function to get a list of files and sub-directories
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void GetFilesInDirectory(std::vector<string> &out, const string &directory)
{
HANDLE dir;
WIN32_FIND_DATA file_data;
if ((dir = FindFirstFile((directory + "/*").c_str(), &file_data)) == INVALID_HANDLE_VALUE)
{out.push_back("Directory is empty (?)"); return;} 
do {
    const string file_name = file_data.cFileName;
    const string full_file_name = directory + "/" + file_name;
    const bool is_directory = (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
//  if (file_name[0] == '.')
//   {continue;}
//  if (is_directory)
//   {continue;}
    out.push_back(full_file_name);
    } while (FindNextFile(dir, &file_data));    
FindClose(dir);
} 

The problem is that is that it doesn't seem to work when the directory contains spaces. How can I correct this problem?

Thanks in advance for your help
Last edited on
Never mind, I was just being stupid and using cin instead of cin.getline
Topic archived. No new replies allowed.