standard way to convert to short path in .net

前端 未结 3 1862
眼角桃花
眼角桃花 2021-01-18 04:41

looking for the standard bug-proofed way to convert \"long names\" such as \"C:\\Documents and settings\" to their equivalent \"short names\" \"C:\\DOCUME~1\"

I need

3条回答
  •  青春惊慌失措
    2021-01-18 05:38

    The trick with GetShortPathName from WinAPI works fine, but be careful when using very long paths there.

    We just had an issue when calling 7zip with paths longer than MAX_PATH. GetShortPathName wasn't working if the path was too long. Just prefix it with "\?\" and then it will do the job and return correctly shortened path.

提交回复
热议问题