UweKeim / ZetaLongPaths

A .NET library to access files and directories with more than 260 characters length.
https://nuget.org/packages/ZetaLongPaths
MIT License
141 stars 28 forks source link
c-sharp file-io files nuget paths pinvoke

Zeta Long Paths

A .NET library to access files and directories with more than 260 characters length.

Introduction

This is a library that provides several classes and functions to perform basic operations on file paths and folder paths that are longer than the MAX_PATH limit of 260 characters.

If you want to use the additional convenience functions of this library with normal non-long paths, and in both .NET Core and Full, please see my new .NET Standard package Zeta Short Paths.

Quick usage

Background

All .NET functions I came across that access the file system are limited to file paths and folder paths with less than 260 characters. This includes most (all?) of the classes in the System.IO namespace like e.g. the System.IO.FileInfo class.

Since I was in the need to actually access paths with more than 260 characters, I searched for a solution. Fortunately a solution exists; basically you have to P/Invoke Win32 functions that allow a special syntax to prefix a file and allow it then to be much longer than the 260 characters (about 32,000 characters).

The library

So I started writing a very thin wrapper for the functions I required to work on long file names.

These resources helped me finding more:

I started by using several functions from the BCL Team blog postings and added the functions they did not cover but which I needed in my project.

Among others, there are the following classes:

Using the code

The project contains some unit tests to show basic functions.

If you are familiar with the System.IO namespace, you should be able to use the classes of the library.

For example to get all files in a given folder path, use the following snippet:

var folderPath = new ZlpDirectoryInfo( @"C:\My\Long\Folder\Path" );

foreach ( var filePath in folderPath.GetFiles() )
{
    Console.Write( "File {0} has a size of {1}", 
        filePath.FullName, 
        filePath.Length );
}

Other libraries

Beside this library, there are other libraries available for accessing longer paths:

Personally, I've used none of these libraries. When I started developing this library either none of the other libraries existed or I have poorly searched.

According to user comments, the Long Path library is rather restricted in terms of functionality; the Delimon library is apparently much more powerful than my library.

Conclusion

Please note that the library currently is limited in the number of provided functions. I will add more functions in the future, just tell me which you require.

I'm using the library in several widely used real-life projects like our Content Management System (CMS), our Test and Requirements Management tool and our Large File Uploader, so the library should be rather stable and reliable.

History

(The full history is always available in the commits list).

(This is not a complete history; only the milestones are noted)