- 论坛徽章:
- 0
|
void EnumFiles(const char* directory, list<string>& fileList)
{
char path[256];
sprintf(path, "%s\\%s", directory, "*.*");
WIN32_FIND_DATA finddata;
HANDLE handle = FindFirstFile(path, &finddata);
do
{
if (strcmp(finddata.cFileName, ".") &&
strcmp(finddata.cFileName, "..")
)
{
string s = finddata.cFileName;
fileList.push_back(s);
}
}while(FindNextFile(handle, &finddata));\
FcloseHandle(handle );
}
EnumFilesI(const char* directory)
{
stack<string> direstoryStack;
direstoryStack.push(directory);
while (!direstoryStack.empty())
{
list<string> fileList;
string s = direstoryStack.top();
direstoryStack.pop();
EnumFiles(s.c_str(), fileList);
for (list<string>::iterator it = fileList.begin(); it != fileList.end(); it++)
{
string s2 = *it;
char path[256];
sprintf(path, "%s\\%s", s.c_str(), s2.c_str());
WIN32_FIND_DATA finddata;
HANDLE handle = FindFirstFile(path, &finddata);
if (handle.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
direstoryStack.push(path);
}
else
{
OutputDebugString(path);
}
}
}
} |
|