Maximal path and maximal file name length

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Where in .NET are definded constants for maximal file name length and
maximal file path?

Thanks,

Lubomir
 
Hello Lubomir,

On Windows-based platforms, paths must be less than 248 characters and file
names must be less than 260 characters.

L> Hi,
L>
L> Where in .NET are definded constants for maximal file name length and
L> maximal file path?
L>
L> Thanks,
L>
L> Lubomir
L>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
| Hello Lubomir,
|
| On Windows-based platforms, paths must be less than 248 characters and
file
| names must be less than 260 characters.


Well I know it's documented like this in the .NET IO claas API's, but
unfortunately it's completely wrong.
The maximum path length is 260 characters maximum including a terminating 0
character.
The maximum file component length is 256 characters including a terminating
0 charecter.
A file path consists of following components:
- drive component (drive letter, a colon: backslash),
- directory components, and
- a file name component

So this "c:\255 chars. filename"
and this ".\255 chars. filename"
are valid paths...

while this is not: "c:\256 chars filename" ...
filename component exceeds 256 characters(excluding the 0 character)

That means that we can say that the largest filename component length is 255
characters, that is 260 characters - the drive component lenth - 1.

Willy.
 
Willy Denoyette said:
| Hello Lubomir,
|
| On Windows-based platforms, paths must be less than 248 characters and
file
| names must be less than 260 characters.


Well I know it's documented like this in the .NET IO claas API's, but
unfortunately it's completely wrong.
The maximum path length is 260 characters maximum including a terminating 0
character.
The maximum file component length is 256 characters including a terminating
0 charecter.
A file path consists of following components:
- drive component (drive letter, a colon: backslash),
- directory components, and
- a file name component

So this "c:\255 chars. filename"
and this ".\255 chars. filename"
are valid paths...

while this is not: "c:\256 chars filename" ...
filename component exceeds 256 characters(excluding the 0 character)

That means that we can say that the largest filename component length is 255
characters, that is 260 characters - the drive component lenth - 1.

Willy.


Hi,

Thanks for answers. I am familiar with those numbers from C++6.0 projects,
where I could use built-in constant MAX_PATH.

Similar aproache I would like to use in C# projects. I want to avoid using
hardcoded number 260. I prefer to use constant provided by the framework, but
I don't know where are these constant defined. Are there any at all?

Thanks for help.

Lubomir
 
Hello Lubomir,

There is no constant for this. If u exceed the lenght of directory name u
just get exception

L> "Willy Denoyette [MVP]" wrote:
L>L> Hi,
L>
L> Thanks for answers. I am familiar with those numbers from C++6.0
L> projects, where I could use built-in constant MAX_PATH.
L>
L> Similar aproache I would like to use in C# projects. I want to avoid
L> using hardcoded number 260. I prefer to use constant provided by the
L> framework, but I don't know where are these constant defined. Are
L> there any at all?
L>
L> Thanks for help.
L>
L> Lubomir
L>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
Hi Michael,

Thank you for help.


Michael Nemtsev said:
Hello Lubomir,

There is no constant for this. If u exceed the lenght of directory name u
just get exception

L> "Willy Denoyette [MVP]" wrote:
L>L> Hi,
L>
L> Thanks for answers. I am familiar with those numbers from C++6.0
L> projects, where I could use built-in constant MAX_PATH.
L>
L> Similar aproache I would like to use in C# projects. I want to avoid
L> using hardcoded number 260. I prefer to use constant provided by the
L> framework, but I don't know where are these constant defined. Are
L> there any at all?
L>
L> Thanks for help.
L>
L> Lubomir
L>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
| "Willy Denoyette [MVP]" wrote:
|
| >
| > | > | Hello Lubomir,
| > |
| > | On Windows-based platforms, paths must be less than 248 characters and
| > file
| > | names must be less than 260 characters.
| >
| >
| > Well I know it's documented like this in the .NET IO claas API's, but
| > unfortunately it's completely wrong.
| > The maximum path length is 260 characters maximum including a
terminating 0
| > character.
| > The maximum file component length is 256 characters including a
terminating
| > 0 charecter.
| > A file path consists of following components:
| > - drive component (drive letter, a colon: backslash),
| > - directory components, and
| > - a file name component
| >
| > So this "c:\255 chars. filename"
| > and this ".\255 chars. filename"
| > are valid paths...
| >
| > while this is not: "c:\256 chars filename" ...
| > filename component exceeds 256 characters(excluding the 0 character)
| >
| > That means that we can say that the largest filename component length is
255
| > characters, that is 260 characters - the drive component lenth - 1.
| >
| > Willy.
|
|
| Hi,
|
| Thanks for answers. I am familiar with those numbers from C++6.0 projects,
| where I could use built-in constant MAX_PATH.
|
| Similar aproache I would like to use in C# projects. I want to avoid using
| hardcoded number 260. I prefer to use constant provided by the framework,
but
| I don't know where are these constant defined. Are there any at all?
|
| Thanks for help.
|
| Lubomir
|

There are no such constants defined in the FCL, the IO namespace classes are
wrappers arround the Win32 ANSI IO API's, so the same values apply. Anyway
when you exceed the max. path size you will get an exception thrown on you.
Note also that you can open files using the UNICODE version of the
CreateFile API through PInvoke, and use the file handle returned in a
FileStream instance, that way you can access files with a path name max. up
to 32768 bytes.

Willy.
 
Back
Top