DirectoryInfo, FileInfo and very long path
Asked Answered
D

5

12

I try to work with DirectoryInfo, FileInfo with very long path.

  • I try use \\?\c:\long path (i got illegal caracter with fileInfo and DirectoryInfo)
  • I try use file://c:/long path (i got uri not supported)

Can i use ~ in a path or something else.

I read this post but i would like to use another way that call a API. Is it any other solutions ?

There is an article from microsoft for use \\? in file path link text

The question is how can i work with very long path, and DirectoryInfo, and FileInfo for path who are more longer that 256 char

Daubery answered 8/9, 2009 at 13:23 Comment(2)
AlphaFS github.com/alphaleonis/AlphaFS may have bugs but works fine for me to use Directory.GetFiles(,,SearchOption.AllDirectories) . Download and built in VS2017 which produce dlls for NetFx45/46/47/20, used in VS2019, nice.Woodwork
Does this answer your question? Best way to resolve file path too long exceptionOcana
B
11

Looking at the Long Paths in .NET blog post series, it looks like going to the Win32 API through P/Invoke is the only solution at the moment, other than restructuring your directories so that you don't hit the limit.

Bun answered 8/9, 2009 at 13:34 Comment(0)
E
13

The Library is available again on this location.

This is a .NET Library written against .NET Framework 2.0 and can be used to access very long folder and files from a .NET application.

Since the .NET Framework does not support long filenames :-( I had to write a library that calls the WIN32 API and wraps those functions like System.IO. While it is not a complete replica of the System.IO it does have most objects and functions available.

Delimon.Win32.IO replaces basic file functions of System.IO with long path names support for characters up to 32,767 Characters So bye bye MAX_PATH problem

Did you ever run into this problem?

System.IO.PathTooLongExceptionwas unhandled.

Message:

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Eightieth answered 19/3, 2012 at 20:30 Comment(1)
Delimon.Win32.IO seems to be close sourced from a company. AlphaFS github.com/alphaleonis/AlphaFS may have bugs but works fine for me to use Directory.GetFiles(,,SearchOption.AllDirectories)Woodwork
B
11

Looking at the Long Paths in .NET blog post series, it looks like going to the Win32 API through P/Invoke is the only solution at the moment, other than restructuring your directories so that you don't hit the limit.

Bun answered 8/9, 2009 at 13:34 Comment(0)
P
6

The Delimon.Win32.I​O Library (V4.0) is also available, it is written against .NET Framework 4.0 and can be used either on x86 & x64 systems.

Pinguid answered 16/2, 2013 at 5:12 Comment(1)
Delimon.Win32.IO seems to be close sourced from a company. AlphaFS github.com/alphaleonis/AlphaFS may have bugs but works fine for me to use Directory.GetFiles(,,SearchOption.AllDirectories)Woodwork
I
5

A way I solved this issue in the past was using the library from Delimon called Delimon.Win32.IO. It looks like his site http://www.delimon.be is down at the moment. But I had used it on a project in the past and it worked like a champ. I can try to track it down for you later this evening or just try to find a valid link to it somewhere via google. Cheers. Here's another link talking discussing this issue.

http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/2541a9b9-acd7-4338-89b1-dfc0408e41b5

Intent answered 8/9, 2009 at 14:51 Comment(0)
N
1

As of .NET 4.6.2, this issue can be resolved with a change to the local machine's group policy, allowing for long paths on Win 10+ and Server 2016+.

Tested and confirmed.

https://blogs.msdn.microsoft.com/jeremykuhne/2016/07/30/net-4-6-2-and-long-paths-on-windows-10/

Neighboring answered 17/9, 2017 at 18:51 Comment(3)
did not work for meThreadgill
Did you restart the PC after making the changes? Are you sure the group policy you changed is being applied to your user?Neighboring
Yes. Still did not work for me after a reboot (Windows Server LTSC 2022). I ended up using AlphaFS 🤷‍♂️Threadgill

© 2022 - 2024 — McMap. All rights reserved.