Last active
October 14, 2016 21:16
-
-
Save d-schmidt/9d48cb76ebf26f531ef3 to your computer and use it in GitHub Desktop.
Circumvent 260 MAX_PATH charlength in Windows API in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath | |
// http://stackoverflow.com/questions/1880321/why-does-the-260-character-path-length-limit-exist-in-windows | |
// converts a relative path like "abc\" or a filename like "savehere.zip" | |
// to full escaped path \\?\c:\currentdir\abc\ | |
// note that all slashes have to be backslashes | |
func FuckWin(path string) string { | |
pwd, err := os.Getwd() | |
if err != nil { panic(err) } | |
result := pwd + "\\" + path | |
if len(result) > 259 { | |
result = "\\\\?\\" + result | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment