Replies: 8 comments
-
In general you can't compare two files for equivalence just by comparing the filenames. For example you could have different case for the drive letter or path, likewise if there is a symbolic or hard-link in the path, or if it is a network drive and comparing a mounted drive versus a UNC path. When it comes to case, the case sensitivity is a property of the file system itself not the running platform. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reminder, let me clarify my report: It's different because the FullName of one is It's not a case about case sensitivity, but I agree that it may relates to symlink / filesystem. I think it maybe a bug so.. |
Beta Was this translation helpful? Give feedback.
-
I am not suggesting it is a bug, it is simply a feature of file paths and file names. File paths identity the file but there is no contract that says any other path can't resolve to the same file. |
Beta Was this translation helpful? Give feedback.
-
Is there a way to get a normalized path for existing dir? I tried |
Beta Was this translation helpful? Give feedback.
-
You may have to examine each directory component in the path to get the correct case for the file, eg if you had said "c:\program files" then you would want "C:\Program Files" back again. |
Beta Was this translation helpful? Give feedback.
-
And if you have a symbolic link along the path, do you need that section replaced by the value of the symbolic link? |
Beta Was this translation helpful? Give feedback.
-
Depending on your actual use-case, it may be simplest to simply remove all trailing slashes ( [System.IO.Path]::DirectorySeparatorChar ) on file paths. However for comparison you need to know whether to do case-sensitive or case-insensitive compare. But you can't remove the trailing slash if it refers to the root directory otherwise you convert the path to a relative directory. An alternative might be to always add a trailing slash to a directory name if it is not there, that way you can tell if it refers to a file or a directory, and you avoid the problem with root directories being treated differently. |
Beta Was this translation helpful? Give feedback.
-
I found a same issue report #4299 . For my case, I verify each folder and add trailing slash then compare them. |
Beta Was this translation helpful? Give feedback.
-
It may or may not a pwsh issue - dotnet is suspecious too.
It shows that DirectoryInfo keeps the trailing slash somehow, which makes this inconsistent.
Tested on pwsh 7.2.7 + Windows 11.
Beta Was this translation helpful? Give feedback.
All reactions