I have a script that accepts a directory as an argument from the user. I'd like to display the name of the directory path as it is displayed in Windows. I.e.,
PS C:\SomeDirectory> cd .\anotherdirectory
PS C:\AnotherDirectory> . .\myscript.ps1 "c:\somedirectory"
C:\SomeDirectory
How do I retrieve "C:\SomeDirectory" when given "c:\somedirectory"?
The accepted answer only gets the correct case of the file. Parent paths are left with the case provided by the user. Here's my solution.
I've integrated the above code into Resolve-PathCase, part of the Carbon PowerShell module. Disclaimer: I'm the owner/maintainer of Carbon.
This should work:
I found a different and simpler approach using PowerShell wild cards.
Using Christian's
GetDirectories
suggestion, here's another solution that's not quite as involved:EDIT: Thanks for all the help.
Btw, all I wanted this for was to use in a little utility script overriding the default cd alias, allowing me to specify some 'root' directories that are searched if the path doesn't exist relative to the current directory. I.e., it allows me to
cd Documents
,cd trunk
,cd Release-10.4
regardless of my current location. And it annoyed me to have the prompt in the case that I entered it, instead of its actual case.