Long paths in Python on Windows
Let me just simplify this for anyone looking for a straight answer:
- Path needs to be unicode, prepend string with
u
likeu'C:\\path\\to\\file'
- Path needs to start with
\\\\?\\
(which is escaped into\\?\
) likeu'\\\\?\\C:\\path\\to\\file'
- No forward slashes only backslashes:
/
-->\\
- It has to be an absolute path; it does not work for relative paths
Well it seems that, as always, I've found the answer to what's been bugging me for a week twenty minutes after I seriously ask somebody about it.
So I've found that I need to make sure two things are done correctly:
- The path can contain only backslashes, no forward slashes.
- If I want to do something like list a directory, I need to end the path with a backslash, otherwise Python will append
/*.*
to it, which is a forward slash, which is bad.
Hope at least someone will find this useful.