"A .NET library to access files and directories with more than 260 characters length
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:
- "Long Paths in .NET" on the BCL Team Blog
- pinvoke.net for finding signatures of Win32 functions
- Using long path syntax with UNC, MSDN
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 pathsZlpDirectoryInfo
- A class similar to System.IO.DirectoryInfo that wraps functions to work on folder pathsZlpIOHelper
- A set of static functions to provide similar features as theZlpFileInfo
andZlpDirectoryInfo
class but in a static contextZlpPathHelper
- A set of static functions similar to System.IO.Path that work on paths..."
Do we need another Long Path/MAX_PATH library? Sigh, yes, we do. Because we're still dealing with long path issues and we still don't good support for them in the OS or .Net framework. Granted I deal with this more often than many due to my day job, but still I've been seeing more and more comments/issues/problems/etc due to max_path issues.
Related Past Post XRef:
AlphaFS v1.5 Released (think "The 'Long Path' IO support the BCL doesn't yet have..." or "Don't 'W' [Wide/Unicode API/etc] P/Invoke your Path API's when AlphaFS has done it already for you..." or "How I learned to love and use Volume Shadow Service paths from .Net")
AlphaFS – Some Max_Path, Transactional NTFS, hard links, and more .Net System.IO.File/Path/Directory Help (alpha)
The Long Path for the BCL Team
Introduction of the BCL CodePlex project (code samples, previews, prototypes, etc from the BCL team) – Includes “Long Path” library direct from the BCL Team (think “Breaking out of MAX_PATH”)
Subsytem for Unix (SUA) Utilities and SDK For Windows 2008 and Vista SP1
The PInvoke tool you've been looking for all this time... the "PInvoke Interop Assistant"
Using GetFileAttributes to Test for File Existence
Unicode Path Fun...
No comments:
Post a Comment
NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...
ALL comments are moderated. I will review every comment before it will appear on the blog.
Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...
I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...
Please see my comment policy for more information if you are interested.
Thanks,
Greg
PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...