1

我已经调试过了,但我仍然不知道可能是什么罪魁祸首。

#ifndef UNICODE 
#define UNICODE
#endif


#include <stdio.h>
#include <Windows.h>


void EndWithBackslash(TCHAR* string)
{
    if(string[wcslen(string)-1] != TEXT('\\')) wcscat(string,TEXT("\\"));
}


void Browse(const TCHAR* curdir)
{
    HANDLE hFoundFile;
    WIN32_FIND_DATA foundFileData;
    TCHAR buffer[MAX_PATH];

    wcscpy(buffer,curdir);

    EndWithBackslash(buffer);

    SetCurrentDirectory(buffer);

    hFoundFile = FindFirstFileEx(TEXT("*"),FINDEX_INFO_LEVELS::FindExInfoBasic,&foundFileData ,FINDEX_SEARCH_OPS::FindExSearchLimitToDirectories ,NULL , NULL);

    if(hFoundFile != INVALID_HANDLE_VALUE)
    {
        do
        {
            if ((foundFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && wcscmp(foundFileData.cFileName,TEXT(".")) && wcscmp(foundFileData.cFileName,TEXT("..")) )
            {   
                EndWithBackslash(buffer);
                wcscat(buffer,foundFileData.cFileName);
                wprintf(TEXT("%s\n"),buffer);


                Browse(buffer);
            }
        }
        while(FindNextFile(hFoundFile,&foundFileData));
        FindClose(hFoundFile);


    }
}

int main(void) 
{   
    Browse(TEXT("F:\\"));

    system("Pause");
    return 0;
}

输出:

F:\$RECYCLE.BIN
F:\$RECYCLE.BIN\S-1-5-21-1271883188-2384997935-49719322-1000
F:\$RECYCLE.BIN\希捷
F:\$RECYCLE.BIN\希捷\希捷Dashboard 2.0
F:\$RECYCLE.BIN\Seagate\Seagate Dashboard 2.0\System Volume Information
F:\$RECYCLE.BIN\Seagate\Seagate Dashboard 2.0\System Volume Information\Video

“第一层”到底长什么样:

在此处输入图像描述

你能指出我的错误吗?

4

1 回答 1

2

内部应该是:

            TCHAR pszItemPath[MAX_PATH];
            wcscpy(pszItemPath, buffer);
            // NOTE: Now when we took a copy of buffer, we don't touch it so that next iteration would have it good and untouched
            EndWithBackslash(pszItemPath);
            wcscat(pszItemPath, foundFileData.cFileName);
            wprintf(TEXT("%s\n"), pszItemPath);
于 2012-09-08T20:20:49.960 回答