解决方案 »

  1.   

    據測試在 Windows 資源管理器中路徑超過 MAX_PATH 長度的文件是沒法通過雙擊打開的,但是程序是可以訪問的。如果你需要訪問超長路徑,必須用 Unicode 版的函數。在很多地方微軟都這樣說過:
    In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 widecharacters, call the Unicode version of the function and prepend "\\?\" to the path.
    WIN32_FIND_DATAW wfd = { 0 };
    HANDLE hFind = FindFirstFileW(L"\\\\?\\C:\\Windows\\*.exe", &wfd);
    if (hFind == INVALID_HANDLE_VALUE) {
        do {
            printf("%S\n", wfd.cFileName);
        } while (FindNextFileW(hFind, &wfd));
        FindClose(hFind);
    }同樣,其他的 API 如 CreateFile 也必須加 \\?\ 前綴,否則不能訪問超過 MAX_PATH 長度的路徑。
      

  2.   

    WIN32_FIND_DATAW wfd = { 0 };
    HANDLE hFind = FindFirstFileW(L"\\\\?\\C:\\Windows\\*.exe", &wfd);
    if (hFind != INVALID_HANDLE_VALUE) {
        do {
            printf("%S\n", wfd.cFileName);
        } while (FindNextFileW(hFind, &wfd));
        FindClose(hFind);
    }