Retrieve proper filename case without using Directory.GetFiles()

D

Devon

Is it possible to retrieve a proper/invariant file or directory name using a
lowercase full path string without having to resort to a call to
GetDirectories()/GetFiles() using the directory/filename as the search
string? While Path, FileInfo, and DirectoryInfo all store the path
information, they use the path case passed to them, so passing a lowercase
path to Path.GetFullPath() will return a lowercase full path. TIA
 
I

Ignacio Machin ( .NET/ C# MVP )

Is it possible to retrieve a proper/invariant file or directory name using a
lowercase full path string without having to resort to a call to
GetDirectories()/GetFiles() using the directory/filename as the search
string? While Path, FileInfo, and DirectoryInfo all store the path
information, they use the path case passed to them, so passing a lowercase
path to Path.GetFullPath() will return a lowercase full path. TIA

Hi,

Not that I know of,
just to confirm, do you want to get the path in the way it's in the
filesystem?
 
D

Devon

Right - given a full path in lowercase, I need to retrieve the path as
present in a local or remote filesystem, which will be, for the majority of
cases, NTFS
 
C

Ciaran O''Donnell

Couldnt see a .NET way to do this as the FileInfo class uses the string you
give it to do fill the FullName property.
So I thought I would knock you up a class to do this. It calls the Windows
Api to get the proper name for each of the folders in the path and then the
file too. It might not be the most perfect implementation as I just knocked
it up for you in about 10 minutes.
I posted it on my blog (below) so let me know what you think.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top