Click here to Skip to main content
Email Password   helpLost your password?

Introduction

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

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.

Currently 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 ZetaDirectoryInfo( @"C:\My\Long\Folder\Path" );

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

Summary

This article quickly introduced a library to deal with long file names when accessing files and folders.

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, below in the comments section of this article.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Generalhttp://alphafs.codeplex.com/
Uwe Keim
2:57 5 Jan '10  
Seems that http://alphafs.codeplex.com [^] provides something similar (and much more advanced) to my library.

Check it out, if you like.

My personal 24/7 webcam
Zeta Test - Intuitive, competitive Test Management environment for Test Plans and Test Cases. Download now!
Zeta Producer Desktop CMS - Intuitive, very easy to use. Download now!

GeneralLong awaited
reisenklaus
11:57 26 Nov '09  
Since I'm programming round the filesystem for some time, this library is a long awaited one for me. To be honest, I really didn't know how to deal with (too) long paths ..
Thank you very much!
StyrianOak
GeneralRe: Long awaited
Uwe Keim
12:07 26 Nov '09  
Thanks for your kind reply! Great that you like it!

My personal 24/7 webcam
Zeta Test - Intuitive, competitive Test Management environment for Test Plans and Test Cases. Download now!
Zeta Producer Desktop CMS - Intuitive, very easy to use. Download now!

GeneralAdditional features
hardsoft
9:32 25 Nov '09  
Would love to see functions/methods to move, delete, rename files.

Looking forward to your next release.
GeneralRe: Additional features
Uwe Keim
9:50 25 Nov '09  
Very good suggestions. Thank you!

My personal 24/7 webcam
Zeta Test - Intuitive, competitive Test Management environment for Test Plans and Test Cases. Download now!
Zeta Producer Desktop CMS - Intuitive, very easy to use. Download now!


Last Updated 25 Nov 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010