Skip to content

Instantly share code, notes, and snippets.

@d-schmidt
Last active October 14, 2016 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-schmidt/9d48cb76ebf26f531ef3 to your computer and use it in GitHub Desktop.
Save d-schmidt/9d48cb76ebf26f531ef3 to your computer and use it in GitHub Desktop.
Circumvent 260 MAX_PATH charlength in Windows API in golang
// 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