簡體   English   中英

“ DriveLetter:SomeDirectory”上的Path.GetFullPath意外行為

[英]Path.GetFullPath unexpected behavior on “DriveLetter:SomeDirectory”

我正在嘗試使用答案中建議的Path類來獲取目錄路徑是否有效。

但是,盡管我期望Path.GetFullName("C:SomeDirectory") (不帶任何斜杠)引發異常,但它會返回C:\\Windows\\system32\\SomeDirectory

另外,如果我編寫Directory.Create("C:SomeDirectory")它會嘗試再次在C:\\Windows\\system32下創建目錄。

例如,當我嘗試輸入C:drivers到Windows資源管理器中的地址欄時,出現錯誤Windows cannot find file. Check the spelling and try again. Windows cannot find file. Check the spelling and try again.

命令行在cd C:drivers也給出了錯誤。

這是預期的行為嗎?

是的,C:告訴它哪個驅動器。 如果要從根目錄開始運行,則路徑的其余部分必須以根目錄'\\'開頭-否則,它將僅附加到當前目錄中。

Path和Uri方法在這些方面非常具體。

所有路徑都相對於當前工作目錄-但以\\開頭的路徑使其相對於該驅動器的根目錄-在命令行上也相同

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM