Reputation: 17593
An application that has been running just fine with Windows XP and Windows 7 suddenly developed problems with Windows 10 Pro. However, with Windows 10 IoT Enterprise, it seems to work fine. It also seemed to work fine back in May of 2018 with Windows 10, yet with newer installs of Windows 10, it doesn't work.
After some investigation, we found that the application seems to be unable to create the set of files that it uses for persistent data with Windows 10 Pro.
Looking further, we found that the complete pathname was incorrect. It appears that the pathname to the directory where files were being stored, though not properly constructed, worked fine with Windows XP and Windows 7, but not with Windows 10 Pro.
The pathname being generated looked like this (those are path backslashes and not C/C++ backslashes for escaping a character):
\C:\DirA\DirB\DirC
while the corrected pathname being generated looks like this:
\\.\C:\DirA\DirB\DirC
Reading MSDN's article on Naming Files, Paths, and Namespaces, I am a bit confused about what appears to be a number of different ways that a valid pathname can be constructed. It appears that different Windows filesystems (FAT16, FAT32, NTFS, etc.) have different naming conventions.
What is the pathname format I should use so that my application will be able to create and open files in a specific directory on a local drive C:
with multiple different versions of Windows? I am specifically interested in Windows 7, POSReady 7, Windows 10, and Windows 10 IoT Enterprise (which is not the same as Windows 10 IoT).
I am using the Win32 API CreateFile()
function to create/open the files.
Upvotes: 3
Views: 2293
Reputation: 596287
What is the pathname format I should use so that my application will be able to create and open files in a specific directory on a local drive
C:
with multiple different versions of Windows?
You should be using:
C:\DirA\DirB\DirC
Or, if you need to access a pathname longer than MAX_PATH
, and don't/can't opt in to the new longPathAware
feature introduced in Windows 10 version 1607:
\\?\C:\DirA\DirB\DirC
DO NOT use \C:\DirA\DirB\DirC
, this is not correctly formatted.
You should not need to use \\.\C:\DirA\DirB\DirC
, though it will work. Just be aware that:
The
"\\.\"
prefix will access the Win32 device namespace instead of the Win32 file namespace.
Typically, you would use \\.\
only when accessing local devices, like physical volumes, serial/parallel ports, named pipes, mailslots, etc. Not when accessing entries on the file system.
Upvotes: 7