Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Windows, when should you use the "\\\\?\\" filename prefix?

I came across a c library for opening files given a Unicode filename. Before opening the file, it first converts the filename to a path by prepending "\\?\". Is there any reason to do this other than to increase the maximum number of characters allowed in the path, per this msdn article?

It looks like these "\\?\" paths require the Unicode versions of the Windows API and standard library.

like image 803
kgriffs Avatar asked Dec 04 '08 17:12

kgriffs


People also ask

What does a filename prefix mean?

The Filename Prefix field can be used to strip off a common prefix from image filenames, to enable the images to be linked to object accession numbers or system IDs.

Why do people use _ in file names?

Removing the space or underscore reduces the length of the file name but by using capital letters to differentiate between the words, the file name is still readily recognisable.


2 Answers

Yes, it's just for that purpose. However, you will likely see compatibility problems if you decide to creating paths over MAX_PATH length. For example, the explorer shell and the command prompt (at least on XP, I don't know about Vista) can't handle paths over that length and will return errors.

like image 196
xahtep Avatar answered Oct 01 '22 01:10

xahtep


The best use for this method is probably not to create new files, but to manage existing files, which someone else may have created.

I managed a file server which routinely would get files with path_length > MAX_PATH. You see, the users saw the files as H:\myfile.txt, but on the server it was actually H:\users\username\myfile.txt. So if a user created a file with exactly MAX_PATH characters, on the server it was MAX_PATH+len("users\username").

(Creating a file with MAX_PATH characters is not so uncommon, since when you save a web page on Internet Explorer it uses the page title as the filename, which can be quite long for some pages).

Also, sharing a drive (via network or usb) with a Mac or a Linux machine, you can find yourself with files with names like con, prn or lpt1. And again, the prefix lets you and your scripts handle those files.

like image 20
itsadok Avatar answered Oct 01 '22 00:10

itsadok