2017-06-13 79 views
0

在我的previous unclear question之後,我以某種方式能夠創建一個長路徑名稱的目錄。但是,如果我嘗試通過添加一個長路徑名稱前綴來訪問它,它仍然會拋出一個錯誤,如下所示。SetCurrentDirectoryW中的錯誤206

ERROR_FILENAME_EXCED_RANGE 
206 (0xCE) 
The filename or extension is too long. 

這裏是我使用(在Windows 7上使用VS 2015年更新3編譯)

#include <iostream> 
#include <windows.h> 

int main() 
{ 
    const std::wstring wdir_path (L"\\\\?\\c:\\temp\\aLongPathnameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent\\aLongPathNameComponent"); 

    if (!SetCurrentDirectoryW(wdir_path.c_str())) 
    { 
     printf("SetCurrentDirectory failed (%d)\n", GetLastError()); 
    } 

    return 0; 
} 

接下來的代碼片段,我試着用版本比1607更高的Windows 10運行此如前所述在msdn中,我設置了註冊表項並重建了上面的代碼,但是當我運行它時,我仍然得到相同的錯誤。我多次閱讀文檔,我不確定我在這裏做錯了什麼。任何人都可以請我指出正確的方向嗎?

更新

1)這裏是我使用的Windows 7

<?xml version='1.0' encoding='UTF-8' standalone='yes'?> 
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> 
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> 
    <security> 
     <requestedPrivileges> 
     <requestedExecutionLevel level='asInvoker' uiAccess='false' /> 
     </requestedPrivileges> 
    </security> 
    </trustInfo> 
</assembly> 
<application xmlns="urn:schemas-microsoft-com:asm.v3"> 
    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"> 
     <ws2:longPathAware>true</ws2:longPathAware> 
    </windowsSettings> 
</application> 

在2提到我也是在註冊表項中增加了一個新的DWORD值)清單文件。但是,在Windows 7上,它不起作用。

2)在Windows 10上,註冊表項方法起作用。我按照文檔修改了以下注冊表項

HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled (Type: REG_DWORD) 

如果我禁用它,則會失敗,反之亦然。

+0

是的,我沒有設置清單條目和註冊表鍵。但沒有運氣。這是否意味着SetCurrentDirectoryW對長路徑名稱的支持被破壞了?只是好奇。 – Recker

+0

Windows 10的版本** 1607 **使長路徑名稱限制得以放寬。 *「1606」*在你的問題中只是一個錯字?你能否包含你的清單文件?另外,請注意[文檔](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365530.aspx):*「空字符前的最後一個字符必須是反斜槓('\' )。「* @DavidHeffernan:文檔顯式調用,您可以啓用此特定API的長路徑感知,從Windows,版本1607開始。文檔是錯誤的,還是您指的是其他限制? – IInspectable

+0

@IInspectable添加對問題的更新。 – Recker

回答

2

除了修改註冊表,您還必須在應用程序清單中包含longPathAware設置。即在documentation描述:

您也可以使每個應用程序通過 清單中的新長路徑的行爲:XML

<application xmlns="urn:schemas-microsoft-com:asm.v3"> 
    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"> 
     <ws2:longPathAware>true</ws2:longPathAware> 
    </windowsSettings> 
</application> 

這些目錄管理功能,再也不用 MAX_PATH限制如果選擇加入長路徑行爲: CreateDirectoryW,CreateDirectoryExW GetCurrentDirectoryW RemoveDirectoryW SetCurrentDirectoryW。

在您的問題中找到的清單無效。 application元素應在assembly之內。

<!-- language: xml --> 

<?xml version='1.0' encoding='UTF-8' standalone='yes'?> 
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> 
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> 
    <security> 
     <requestedPrivileges> 
     <requestedExecutionLevel level='asInvoker' uiAccess='false' /> 
     </requestedPrivileges> 
    </security> 
    </trustInfo> 
    <application xmlns="urn:schemas-microsoft-com:asm.v3"> 
    <windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"> 
     <ws2:longPathAware>true</ws2:longPathAware> 
    </windowsSettings> 
    </application> 
</assembly> 

最後,任何提及的是Windows 7都沒有提及這一點。只能從Windows 10 1607中刪除MAX_PATH限制。

2

此功能的MSDN文檔異常糟糕。大多數將路徑作爲輸入的函數將允許您通過在L"\\?\"前加上路徑來繞過MAX_PATH限制,但此函數不是其中的一個。如果您查看文檔的older version,則無論您在Windows 8和更早版本上做什麼,您都會看到MAX_PATH是記錄的限制。

當在Windows 10(1607)中添加新的長路徑策略時,大多數函數在灰色陰影框中的文檔中添加了一條關於此的註釋,此功能是放鬆已存在的\\?\前綴在文檔中,但對於此功能,策略和\\?\都是新的,但只有策略位於帶有版本信息的灰色框中,\\?\前綴是正常描述的一部分,因此它看起來像是具有總是在那裏,但事實上它與政策同時記錄在案!

相關問題