文件夹搜索器

int Test(char* g_pcDir)
{
   //LPWIN32_FIND_DATA lpFileData = new WIN32_FIND_DATA();
    WIN32_FIND_DATA FileData;
    HANDLE hSearch;
    char cFileName[ MAX_PATH ];
char cPathName[ MAX_PATH ];
    BOOL fFinished = FALSE;

    // Change current directory.
    SetCurrentDirectory(g_pcDir);

    // Start searching for *.* files in the current directory.
    hSearch = FindFirstFile("*.*", &FileData);
    if (hSearch == INVALID_HANDLE_VALUE)
    {
        printf("\r\n No *.* file was found.");
        fFinished = TRUE;
    }
    while (!fFinished)
    {
       strcpy(cFileName, FileData.cFileName);
        /* 遍历文件夹*/
if (FILE_ATTRIBUTE_DIRECTORY == (FileData.dwFileAttributes & 0xff))
{
if (strcmp(cFileName, "..") != 0
&& strcmp(cFileName, ".") != 0)
{
sprintf(cPathName, "%s\\%s", g_pcDir, cFileName);
Test(cPathName);
}
}
else
{
printf("%s\\%s\n", g_pcDir,cFileName);
}


        //Search next file
        if(!FindNextFile(hSearch, &FileData))
        {
            if (GetLastError() == ERROR_NO_MORE_FILES)
            {
/* find finish */
                fFinished = TRUE;
            }
            else
            {
                printf("\r\n error!");
            }
        }
    }
    //Close the search handle.
     if (!FindClose(hSearch))
    {
        printf("\r\n Couldn't close search handle.");
    }
    return 0;
}

你可能感兴趣的:(文件夹)