473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Path.GetDirectoryName() \\?\ and long directory names?


Hi!

I know, that Path-names should be shorter than MAX_PATH (250), but the
Win32-SDK allows specifiying longer names using the "\\?\" prefix.

As I have an application that accesses files directly using the volume
name instead of the drive letter
(i.e. "\\?\Volume{...}\subdir\file.ext"), I sometimes get an
PathTooLongException, as the total string exceeds 260 characters (due to
the "\\?\Volume{...}\"-part).

Is there any way, to get Path.GetDirectoryName() to honor the "\\?\"
prefix and therefore skip the check for MAX_PATH?

I find it interesting, that GetDirctoryName() and GetFullPath() are the
only two methods checking for the path length, Path.Combine(),
Path.GetFileName(), etc. all work without any problem with the long strings.

Best regards,
Martin

PS: Unfortunately it is no option to use the aliased path ("C:\...")
instead of the full path, as the Path is handed to the application from
external.
Oct 18 '06 #1
5 10254

"Martin Carpella" <ma*************@gmx.netwrote in message
news:87************@msgid.carpella.net...
|
| Hi!
|
| I know, that Path-names should be shorter than MAX_PATH (250), but the
| Win32-SDK allows specifiying longer names using the "\\?\" prefix.
|
| As I have an application that accesses files directly using the volume
| name instead of the drive letter
| (i.e. "\\?\Volume{...}\subdir\file.ext"), I sometimes get an
| PathTooLongException, as the total string exceeds 260 characters (due to
| the "\\?\Volume{...}\"-part).
|
| Is there any way, to get Path.GetDirectoryName() to honor the "\\?\"
| prefix and therefore skip the check for MAX_PATH?
|
| I find it interesting, that GetDirctoryName() and GetFullPath() are the
| only two methods checking for the path length, Path.Combine(),
| Path.GetFileName(), etc. all work without any problem with the long
strings.
|
| Best regards,
| Martin
|
| PS: Unfortunately it is no option to use the aliased path ("C:\...")
| instead of the full path, as the Path is handed to the application from
| external.

The framework does not support volume and device names in the path for it's
file IO methods, nor does it support Unicode path's (path 260 characters),
that means some methods do have to check this constraint, unfortunately some
methods don't care at all about this (Combine) while others don't need to
care (GetFileName).
Anyway, you obtained an handle to a "volume path" by a call to Win32's
CreateFile API (through PInvoke), effectively bypassing the restriction
imposed by the IO namespace classes, that means that you will have to
PInvoke some Win32 API's when you need to deal with issues related to the
imposed restrictions.

Willy.

Oct 18 '06 #2
"Willy Denoyette [MVP]" <wi*************@telenet.bewrites:
Anyway, you obtained an handle to a "volume path" by a call to Win32's
CreateFile API (through PInvoke), effectively bypassing the restriction
imposed by the IO namespace classes, that means that you will have to
PInvoke some Win32 API's when you need to deal with issues related to the
imposed restrictions.
Thanks for your fast response. I almost expected this (and I have no
problem with it), I just wanted to make sure there is no "managed" way
of handling the situation.

Best regards,
Martin
Oct 18 '06 #3
"Willy Denoyette [MVP]" <wi*************@telenet.bewrites:
The framework does not support volume and device names in the path for it's
file IO methods, nor does it support Unicode path's (path 260 characters),
that means some methods do have to check this constraint, unfortunately some
methods don't care at all about this (Combine) while others don't need to
care (GetFileName).
Adding to my previous post, I notice there seems to be a "off-by one"
bug in the .NET framework implementation, as I managed to create a
file with 242 characters in a folder with 18 (total 260) using on-board
means (Explorer -Create new file -rename).
Path.GetDirectory() fails on this with the same PathTooLongException
(telling me, that the total filename must be less than 260 and the
pathname shorter than 248).

Best regards,
Martin
Oct 18 '06 #4

"Martin Carpella" <ma*************@gmx.netwrote in message
news:87************@msgid.carpella.net...
| "Willy Denoyette [MVP]" <wi*************@telenet.bewrites:
|
| The framework does not support volume and device names in the path for
it's
| file IO methods, nor does it support Unicode path's (path 260
characters),
| that means some methods do have to check this constraint, unfortunately
some
| methods don't care at all about this (Combine) while others don't need
to
| care (GetFileName).
|
| Adding to my previous post, I notice there seems to be a "off-by one"
| bug in the .NET framework implementation, as I managed to create a
| file with 242 characters in a folder with 18 (total 260) using on-board
| means (Explorer -Create new file -rename).
| Path.GetDirectory() fails on this with the same PathTooLongException
| (telling me, that the total filename must be less than 260 and the
| pathname shorter than 248).
|
| Best regards,
| Martin

MAX_PATH is defined as 260 including a terminating 0 character, note that
the docs says LESS than 260, but the doc's and the exception message are
wrong when they says 260 is the max filename length, a filename cannot be
longer than the path.
The filename is a component of path, and it's length is 256 character
(including a terminating 0).
To resume: the maximum for path and filename are respectively 259 and 255
characters.

Willy.

Oct 18 '06 #5
"Willy Denoyette [MVP]" <wi*************@telenet.bewrites:
MAX_PATH is defined as 260 including a terminating 0 character, note that
the docs says LESS than 260, but the doc's and the exception message are
wrong when they says 260 is the max filename length, a filename cannot be
longer than the path.
The filename is a component of path, and it's length is 256 character
(including a terminating 0).
To resume: the maximum for path and filename are respectively 259 and 255
characters.
Thanks, I'm aware of the limits, thats why I was so confused when I
encountered the 260-file.

I was absolutely sure I managed to create the file with 260 using only
explorer, but as I wrote a reply emphasizing this, I just tried to
reproduce, just in case... And well, Murphy was right (again). I'm
unable to reproduce a 260 file using Explorer alone ;) So I seam to need
to confess I was wrong and my other file seems to have been created
using Win32-API instead...

Sorry for my mistake.

Best regards,
Martin
Oct 18 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tomek | last post by:
Hello. How to get path to current directory and put this path to object of class String? I found FileSystemView.getHomeDirectory() but it returns path to home directory for example: ...
8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
2
by: Sheila | last post by:
I am hoping someone here has experience with this. I am using Access 97, but if someone has done this in another version I'd appreciate input as well I need to populate a table with subdirectory...
1
by: Alan Searle | last post by:
I have a VBA function which scans directories and reads the filenames (of the contents) out into a table. Mostly this works fine but one of my clients is having a problem and I suspect it is...
2
by: Steven J. Reed | last post by:
I have a Web Service that needs to find a Virtual Directory name, determine the actual path of that directory, then read / write files to that directory. How can I find a virtual directory then...
1
by: topramen | last post by:
does any one here know of a good way to to determine whether or not a given path is a directory (e.g., "c:\mydir") or a file (e.g., "c:\mydir \myfile.txt")? i started attacking this problem by...
0
by: JohnIdol | last post by:
Hi Guys, anyone could help me understand the difference between these two methods? path =...
0
by: jaymehta18 | last post by:
Hi, I have a piece of code which finds the symbolic links in a directory structure and then use the function readlink() to get the actual path of symbolic link. e.g.: i get symbolic link...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.