views:

36

answers:

3

I just stumbled on this article on MSDN that says a path can be 259 characters + NUL termination, but if you prefix it with "\\?\" WinAPI allows you to use the

maximum total path length of 32,767 characters.

Eager to see it working I tried using that prefix from Explorer (On XP SP3) but it doesn't work at all (on any path). If you put \\?\C:\Path\to\an\existing.file on explorer's bar, it will give the "file not found" error.

So I'm confused. Can I code something for (non-ancient) Windows that makes full use of the mentioned path size on NTFS? Why Explorer doesn't use it?

+1  A: 

Before someone tells me to RTFM...

Note that these examples are intended for use with the Windows API functions and do not all necessarily work with Windows shell applications such as Windows Explorer.
[...]
For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to disable all string parsing and to send the string that follows it straight to the file system. For example, if the file system supports large paths and file names, you can exceed the MAX_PATH limits that are otherwise enforced by the Windows APIs.

On a secondary note, this makes me wonder about the possibilities of hiding files (or finding such files) from explorer by using illegal file names.

Camilo Martin
+1  A: 

There is a SET of API calls that are work with extened-paths and some that do not. The MSDN usually mentions this.

Not that if you just type that path into windows explorerunder xp this does not work, because the extened path syntax is just an escape sequence for the WIn32 API and not for windows explorer. Now, In Win7 this does work because many people expected this to work.

Also for long paths, it does help if you change the working directory or open up explorer with a sub-directory as a root.

Dominik Weber
What? "it does help if you change the working directory or open up explorer with a sub-directory as a root" You mean there is a `chroot` for Windows? Or you mean something else?
Camilo Martin
yes- there is a SetCurrentDirectory() And I might be wrong - but At some point in the past i *thought* that helped. At least if the app deals in relative paths, not absolute ones.
Dominik Weber
A: 

Are you asking why all components in Windows do not support it, or are you asking whether it's legal to use these long paths?

You can definitely safely use them, but you may irritate someone who wants to use tools like Explorer to browse them. We see paths like this all the time in the wild. Sometimes people are pretty surprised when they can't use MY_FAVORITE_TOOL to delete it...

jrtipton
I'm actually thinking about developing a file browser that is less stupid than Explorer. I mean, NTFS offers a world of Unix-like possibilities that simply aren't *used* in XP.
Camilo Martin
edit: *"I'm thinking about developing a file browser"* = sometime between now and the end of time.
Camilo Martin