|
楼主 |
发表于 2009-7-29 17:37:47
|
显示全部楼层
找到代码,可是编译进osgmfc里报错~晕死:
void FindFileInDir(char* rootDir, char* strRet)
{
char fname[MAC_FILENAMELENOPATH];
ZeroMemory(fname, MAC_FILENAMELENOPATH);
WIN32_FIND_DATA fd;
ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
HANDLE hSearch;
char filePathName[256];
char tmpPath[256];
ZeroMemory(filePathName, 256);
ZeroMemory(tmpPath, 256);
strcpy(filePathName, rootDir);
BOOL bSearchFinished = FALSE;
if( filePathName[strlen(filePathName) -1] != '\\' )
{
strcat(filePathName, "\\");
}
strcat(filePathName, "*");
hSearch = FindFirstFile(filePathName, &fd);
//Is directory
if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
&& strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
strcpy(tmpPath, rootDir);
strcat(tmpPath, fd.cFileName);
FindFileInDir(tmpPath, strRet);
}
else if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
sprintf(fname, "%-50.50s", fd.cFileName);
strcat(strRet + strRet[strlen(strRet)] , fname);
}
while( !bSearchFinished )
{
if( FindNextFile(hSearch, &fd) )
{
if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
&& strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
strcpy(tmpPath, rootDir);
strcat(tmpPath, fd.cFileName);
FindFileInDir(tmpPath, strRet);
}
else if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )
{
sprintf(fname, "%-50.50s", fd.cFileName);
strcat(strRet + strRet[strlen(strRet)] , fname);
}
}
else
{
if( GetLastError() == ERROR_NO_MORE_FILES ) //Normal Finished
{
bSearchFinished = TRUE;
}
else
bSearchFinished = TRUE; //Terminate Search
}
}
FindClose(hSearch);
} |
|