I'm working on a cross-platform project and want to deal with some paths that can support multi-platforms by PowerShell.
For example, I need to transfer a string of a path from an NTFS of Windows to Linux, access the path from Linux by mounting the NTFS, and deal with the path for other normal purposes.
The procedures can be the following:
The problem is:
c:\uSeRs\usER\TesT.tXt
, even though it represents the real one C:\Users\User\test.txt
c:\uSeRs\usER\TesT.tXt
from C:\Users\User\test.txt
by literal, since they both represent the same resource.Explorer.exe
, it means the information of the original case-sensitive path is just recorded somewhere. From a case-confused path, we can locate a specific item, but how to get its original information that contains its case-sensitive path?There may be too many points. But my key problem can be described as the following target:
C:\Users\User\test.txt
already.c:\uSeRs\usER\TesT.tXt
C:\Users\User\test.txt
as we can see from explorer.exe
I have tried Get-Item
, Get-ItemProperty
and something like here, but they do not work:
#Requires -Version 7.0
$target = 'C:\Users\User\test.txt'
New-Item -Path $target -ItemType File
$known = 'c:\uSeRs\usER\TesT.tXt'
(Get-Item $known).FullName
# C:\uSeRs\usER\TesT.tXt
# 'c' has been converted to `C` but the other parts have not been converted to the target
(Get-Item $known).FullName -eq $target
# False
# see https://stackoverflow.com/a/48845935/17357963
(Get-Item $known).Target
# return $null or empty
(Get-ItemProperty $known).FullName -eq $target
# False
(Get-ItemProperty $known).Target
# return $null or empty
Thanks in advance.
Based on the comments, we worked out the anwser as:
(Get-ChildItem (Split-Path $known) | Where-Object Name -eq (Split-Path $known -leaf)).FullName