8

Possible Duplicate:
Why does the 260 character path length limit exist in Windows?

I'm trying to figure out a way to get around this dreaded 260 character fully qualified path limit and at the same time I wonder why the hell is there a path limit to begin with!? I know to some people 260 seems to be "a lot", but it truly isn't since I ran into this issue.

Basically:
Why must there be a character limit?
How does one get around it?

phuclv
  • 37,963
  • 15
  • 156
  • 475
michael
  • 14,844
  • 28
  • 89
  • 177
  • Heard of Twitter? It has a 140 character limit. That's one reason for the upsurge of interest in URL shorteners like Bitly. – DOK Jan 12 '11 at 18:41
  • it's an old Windows OS limit that is not relevant anymore, excepted that it still has repercussion in lots of OS functionality. But you can now have long file name in the .NET framework. https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/2156195-fix-260-character-file-name-length-limitation – Pac0 Jul 03 '18 at 14:03

3 Answers3

13

Use the \\?\ UNC prefix to break out of "DOS mode" for paths. The max length for UNC paths is 32k characters.

More info here: http://msdn.microsoft.com/en-us/library/aa365247.aspx

dthorpe
  • 35,318
  • 5
  • 75
  • 119
  • 1
    "\\?\" does not make it a UNC, \\?\ supports UNC. – Peter Ritchie Aug 29 '13 at 15:58
  • Each component (\ ... \) has a `lpMaximumComponentLength` value limit (from `GetVolumeInformation` function). – n00dles Nov 03 '15 at 19:06
  • Is there a way to workaround this component limit, to let each component be longer than that specified limit, for e.g the default 255 chars? – Swtsvn Jul 15 '16 at 06:45
  • @Swtsvn how can a component be longer than 255 chars when the maximum file name length is 255 chars? – phuclv Jul 30 '21 at 09:18
10

From the MSDN:

The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".

dthorpe
  • 35,318
  • 5
  • 75
  • 119
Matten
  • 17,365
  • 2
  • 42
  • 64
1

Well, first, this has nothing to do with C# in particular, and everything to do with the Windows API, wherein that limit resides. :)

Take a look at this question and its answers, which will lead you to MSDN: Naming Files, Paths, and Namespaces

Unicode file paths (described in the answers to the question, and the MSDN article) may be as solution, with some caveats.

Community
  • 1
  • 1
Dan J
  • 16,319
  • 7
  • 50
  • 82