473,690 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Path.GetDirecto ryName() \\?\ 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.e xt"), I sometimes get an
PathTooLongExce ption, as the total string exceeds 260 characters (due to
the "\\?\Volume{... }\"-part).

Is there any way, to get Path.GetDirecto ryName() 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.GetFileNam e(), 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 10311

"Martin Carpella" <ma************ *@gmx.netwrote in message
news:87******** ****@msgid.carp ella.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.e xt"), I sometimes get an
| PathTooLongExce ption, as the total string exceeds 260 characters (due to
| the "\\?\Volume{... }\"-part).
|
| Is there any way, to get Path.GetDirecto ryName() 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.GetFileNam e(), 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.bewri tes:
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.bewri tes:
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.GetDirecto ry() fails on this with the same PathTooLongExce ption
(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.carp ella.net...
| "Willy Denoyette [MVP]" <wi************ *@telenet.bewri tes:
|
| 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.GetDirecto ry() fails on this with the same PathTooLongExce ption
| (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.bewri tes:
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
87829
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: C:\Documments and Settings\Thomas Thanks for help.
8
17478
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 request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.IO.IOException: The directory name is invalid.
2
1846
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 names. Example: c:\Tests has the subdirectories test1, test2 and test3. Each directory has a file called test1.txt, test2.txt, test3.txt. I would like to populate a table with just the subdirectory names.
1
2008
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 because of extremely long directory paths. I haven't yet been able to go there and diagnose the problem but I believe that I can sort out most issues: I can probably split the path into its component directories and use this to get around the 255...
2
3675
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 determine it's properties?
1
2559
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 using filesystemobject to check whether or not a directory existed for the path. if so, it was a directory path. if not, i checked to see if a file existed for it. if so, it was a file path. this code is shown below: ...
0
1362
by: JohnIdol | last post by:
Hi Guys, anyone could help me understand the difference between these two methods? path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Replace("file:/", "")); path_Startup = System.IO.Directory.GetCurrentDirectory(); I am getting the same result.
0
1200
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 /home/software/myproject/bin which points to /home/software/myproject/bin-1.0 Now there are 2 problems, readlink() returns me either the full path as metioned (/home/software/myproject/bin-1.0) or it just gives me back bin-1.0 (link could be created...
0
8598
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8951
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8786
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6457
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4322
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1952
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.