I'm looking for a way to get the my local path that includes any camel cases that are used in the names. The primary reason is so I can use the same path to make a call in windows wsl. For example, in windows I can call a file as
c:\FoO\bar.txt
c:\Foo\Bar.txt
and windows will display it as c:\foo\bar.txt
. When I try to enter the WSL with bash I need to know the actual path since Linux is case sensitive.
I have tried using
$PSScriptRoot
Split-path C:\FoO\Bar.txt
(get-Item c:\Foo\Bar.txt).FullName
but they will only provide the path that to call the script.
How do I get my path as it's displayed in the windows os?
I can't just call the full path of the file I need since I can't guarantee the root directory it starting from. I also don't want to burn up cycles doing a find.
What you want is to look at the Target
property you get back from Get-Item
. Fullname
will come back however you typed it initially, but Target
is actually a code property that seems to get the raw path of the object.
(get-Item c:\Foo\Bar.txt).Target
from windows 10 onwards, the Target
property is empty.
(Get-Item '....')
doesn't contain any property that holds the case sensitive name.
however, when getting all child items of a folder, you get all the names case sensitive.
so my solution is like this:
$myCaseInsensitiveFileName = 'c:\FoO\bar.txt'
$allFiles = Get-ChildItem 'c:\' -Recurse
$caseSensitiveName = $allFiles.FullName | Where-Object { $_.FullName -eq $myCaseInsensitiveFileName }
$caseSensitiveName
holds C:\Foo\Bar.txt
.
note:
-eq
operator compares strings case insensitiveIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With