WiteFalcon
asked on
Using Visual C++, how can I retrieve the sub-folders and filenames in a folder, which has space in it's name? It should also work in Vista.
Hi,
I'm trying to list all sub-folders and file names in a directory and I thought it was working till it was tested in Vista. I found out that in Vista if the folder name had a space in it the code i have doesn't work. I'm programming using Visual C++ and using functions from io.h.... I'm attaching the code with this. Any help will be much appreciated.
I'm trying to list all sub-folders and file names in a directory and I thought it was working till it was tested in Vista. I found out that in Vista if the folder name had a space in it the code i have doesn't work. I'm programming using Visual C++ and using functions from io.h.... I'm attaching the code with this. Any help will be much appreciated.
...
struct _finddata_t c_file;
long hFile;
if( (hFile = (long)_findfirst( szPathPattern.c_str(), &c_file )) == -1L)
{
// Nothing in directory
return;
}
else
{
szName = string(c_file.name);
if (c_file.attrib & _A_SUBDIR)
szName = BRACKET_OPEN + szName + BRACKET_CLOSED;
// Add it to the listbox if it passes the filter
if (_matchItem(szName))
_mLbxFiles->addItem(new MyListItem(szName));
}
// Get the other ones
while( _findnext( hFile, &c_file ) == 0 )
{
szName = string(c_file.name);
if (c_file.attrib & _A_SUBDIR)
szName = BRACKET_OPEN + szName + BRACKET_CLOSED;
// Add it to the listbox if it passes the filter
if (_matchItem(szName))
_mLbxFiles->addItem(new MyListItem(szName));
}
_findclose( hFile );
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window