Click here to Skip to main content
Licence CPOL
First Posted 25 Nov 2009
Views 26,233
Downloads 473
Bookmarked 54 times

Zeta Long Paths

By Uwe Keim | 10 Oct 2011 | Unedited contribution
A .NET library to access files and directories with more than 260 characters length

1

2

3
5 votes, 17.9%
4
23 votes, 82.1%
5
4.91/5 - 28 votes
μ 4.89, σa 0.99 [?]

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: 

  • ZlpFileInfo - A class similar to System.IO.FileInfo that wraps functions to work on file paths
  • ZlpDirectoryInfo - A class similar to System.IO.DirectoryInfo that wraps functions to work on folder paths 
  • ZlpIOHelper - A set of static functions to provide similar features as the ZlpFileInfo and ZlpDirectoryInfo class but in a static context 
  • ZlpPathHelper - A set of static functions similar to System.IO.Path that work on paths

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 );
}

When using the functions, please do not encode the paths with the long path syntax (like e.g. \\?\C:\my\path) but pass them as normal paths like c:\my\path or \\myserver\myshare\my\path. The library itself decides whether a path has to be converted and does it automatically. 

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 

  • 2011-10-10 - Fixed an error in ZlpFileInfo.Exists.
  • 2011-03-30 - Fixed a resource leak.
  • 2011-03-27 - Fixed an issue with WIN32_FIND_DATA.
  • 2011-02-22 - Added more functions.  
  • 2011-01-31 - Added functions MoveFile and MoveDirectory
  • 2010-03-24 - Added functions to get file owner, creation time, last access time, last write time.
  • 2010-02-16 - Maintenance release. 
  • 2009-11-25 - First release to CodeProject.com.  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Uwe Keim

Software Developer (Senior)
Zeta Software GmbH
Germany Germany

Member
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He is also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. You can watch him most of the day (and probably night) programming.
 
Some cool, free software from us:
 
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralZeta Long Paths...new functionality requested Pinmembermichaeldjackson14:58 20 Mar '10  
GeneralRe: Zeta Long Paths...new functionality requested PinmvpUwe Keim21:10 21 Mar '10  
GeneralRe: Zeta Long Paths...new functionality requested PinmvpUwe Keim20:15 23 Mar '10  
GeneralRe: Zeta Long Paths...new functionality requested Pinmembermichaeldjackson3:19 24 Mar '10  
GeneralAdditions Pinmembermichaeldjackson14:47 22 Feb '10  
GeneralRe: Additions PinmvpUwe Keim19:33 22 Feb '10  
Generalhttp://alphafs.codeplex.com/ PinsitebuilderUwe Keim2: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 Pinmemberreisenklaus11:57 26 Nov '09  
GeneralRe: Long awaited PinsitebuilderUwe Keim12:07 26 Nov '09  
GeneralAdditional features Pinmemberhardsoft9:32 25 Nov '09  
GeneralRe: Additional features PinsitebuilderUwe Keim9:50 25 Nov '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 11 Oct 2011
Article Copyright 2009 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid