|
-
Nov 28th, 2007, 03:48 PM
#1
Thread Starter
Not NoteMe
[1.0/2.0/3.0] Obtaining Path Capitalisation
Lets say that i've got a path (or file): "D:\Games\WhaTeVer"
I want to get from an uncapitalised string such as "d:\games\whatever" to the Capitalised version (i.e. the actual file\folder).
Anyone know how to do this. I've had a look at the Path, Directory and DirectoryAttribute classes, but unless i'm missing something they don't seem to enforce the correct capitalisation much. (things like DirectoryAttributeObject.FullName simply returns the string used to create it, whether it has the actual file/folder capitalisation correct).
Thanks for any help.
Last edited by SLH; Nov 28th, 2007 at 04:00 PM.
Reason: Edited title
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Nov 28th, 2007, 06:09 PM
#2
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
Given that file system paths are case-insensitive, may I ask why this is important?
-
Nov 28th, 2007, 07:04 PM
#3
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
You would have to capitalize each manually via code as there is no special function for it.
Just split the path into an array and format the elements with proper casing. Then loop through your array to rebuild a string var with the original path but with the proper casing you desire.
Ps, Im taking this is just for presentation effects.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 28th, 2007, 07:31 PM
#4
Thread Starter
Not NoteMe
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
Yeah, it's for presentation.
RobDog, thanks for the help, but i'm not sure how i can format the elements with the proper casing.
The only way of doing this that i can think of is enumerating all folders for every directory in my path, getting the correct case for each folder as i go.
i.e. enumerate all folders in D:\, then searching for 'games' (case insensitive) within that list of folders, matching with Games, then enumerating all folders in D:\Games, then searching for 'whatever', matching with WhaTeVer and so on.
That just seems like i'm getting more information than needed (all the enumerated files). I'd hoped there was a better way, using less calls to IO functions.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Nov 28th, 2007, 07:39 PM
#5
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
You could start with your full path, use Path.GetDirectoryName to get the parent folder, then just get the subfolders of that.
-
Nov 28th, 2007, 07:51 PM
#6
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
Not sure how you are needing things but it sounds like your doing a recursive directory search and building your path that way? I was under the impression you already had the path and needed simple proper casing.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 28th, 2007, 07:56 PM
#7
Thread Starter
Not NoteMe
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
I do already have the path, but i don't have the case sensitive version. What i have is a registry entry, which happens to be all lower case. I want to change it to be the correct case.
The recursive method i described is one method of working out the correct case path, but i'm looking for something that takes less system calls.
EDIT: Thanks jmcilhinney, just saw your post, i'll give that a go and report back.
EDIT#2: Unfortunatly that doesn't work, the GetDirectoryName Method doesn't return the correct case, it keeps the case of the path you give it as an argument.
Last edited by SLH; Nov 28th, 2007 at 08:06 PM.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Nov 28th, 2007, 08:04 PM
#8
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
 Originally Posted by jmcilhinney
You could start with your full path, use Path.GetDirectoryName to get the parent folder, then just get the subfolders of that.
I tell a lie. That doesn't work.
-
Nov 28th, 2007, 08:07 PM
#9
Thread Starter
Not NoteMe
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
Yeah, this one's really bugging me. I might just end up doing the recursive method even though it seems horribly in-efficient.
Still very much open to suggestions though!
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Nov 28th, 2007, 09:49 PM
#10
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
This is a refinement of what you suggested:
vb.net Code:
Private Function GetOriginalPath(ByVal path As String) As String
Dim root As String = IO.Path.GetPathRoot(path)
Dim nodes As New Stack(Of String)
While path <> root
nodes.Push(IO.Path.GetFileName(path))
path = IO.Path.GetDirectoryName(path)
End While
Dim node As String
Dim originalPath As String = root.ToUpper()
While nodes.Count > 0
node = nodes.Pop
originalPath = IO.Directory.GetDirectories(originalPath, node)(0)
End While
Return originalPath
End Function
I forgot we were in C# land. If you need me to convert let me know.
-
Nov 29th, 2007, 09:46 AM
#11
Thread Starter
Not NoteMe
Re: [1.0/2.0/3.0] Obtaining Path Capitalisation
Works great thanks, i had to make a few little changes to deal with paths with a trailing \ and to deal with files but other than that it works great, thanks!
Reputation++ EDIT: Well i would do, but it says i need to spread my reputation around a bit more!
In case anyone needs it, here's the code i've got now:
Code:
private static string GetRealPath(string path)
{
string Root = Path.GetPathRoot(path);
Stack<string> Nodes = new Stack<string>();
string Node;
while (string.Compare(path, Root, StringComparison.OrdinalIgnoreCase) != 0)
{
Node = Path.GetFileName(path);
if(Node != "")
Nodes.Push(Node);
path = Path.GetDirectoryName(path);
}
string RealPath = Root.ToUpper();
while (Nodes.Count > 0)
{
Node = Nodes.Pop();
string[] Directories = Directory.GetDirectories(RealPath, Node, SearchOption.TopDirectoryOnly);
if (Directories.Length == 0)
RealPath = Directory.GetFiles(RealPath, Node,SearchOption.TopDirectoryOnly)[0];
else
RealPath = Directories[0];
}
return RealPath;
}
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|