Any suggestions on the best way to determine that any two of these strings are equivalent paths? I could just loop one char at a time removing redundant and trailing \'s if no one knows of anything better. I'm also afraid there are other nuances that I might not have anticipated. Like, I just thought while typing, what if shortened 8.3 compatible file names were in the path. So maybe some method that relies on the OS a little more would be more "aware" of those nuances.
"C:\\Program Files\\blah blah"
"C:\Program Files\blah blah\"
"C:\\Program Files\\blah blah\"
"C:\Program Files\blah blah"
Compare Paths?
12 posts
GetFullPathName might be able to help out
you could cheat and write a temporary file to the path. If that file is present in the second path, then the two paths are the same.
On the up side, that bypasses any manual handling of short vs long filenames, symbolic paths that may be the same, double backslashes, 'up' modifiers ( \..\ ), etc.
On the down side, it's not a clean method and if you can't write to the path it won't work either.
On the up side, that bypasses any manual handling of short vs long filenames, symbolic paths that may be the same, double backslashes, 'up' modifiers ( \..\ ), etc.
On the down side, it's not a clean method and if you can't write to the path it won't work either.
Originally posted by AndersThat's a good idea ... depending on how GetFullPathName is actually implemented in NSIS.
GetFullPathName might be able to help out
If it's just a wrapper around the GetFullPathNameA function in kernel32 (as I should hope) then it should do the job.
Just call GetFullPathName on each of the two strings in question and then compare them with StrCmp, and they should compare as equal if the strings represent the same path.
Not quite what I need ... I want to compare a string to see whether it contains the CLSID_PROGRAM_FILES directory or any subdirectory thereof, but I think this and some calls to GetParent will do it 😉
For that Daniel, can you not get the length of $PROGRAMFILES, copy that same number of characters from your path to be compared and then compare the result with $PROGRAMFILES?
Stu
Stu
(for the more generic case, there's also...)
Originally posted by Afrow UKYes. Much neater. Thanks.
For that Daniel, can you not get the length of $PROGRAMFILES, copy that same number of characters from your path to be compared and then compare the result with $PROGRAMFILES?
Originally posted by AnimaetherMy goodness that's a hairy piece of scripting! I think I'd much rather write a plugin to do that.
(for the more generic case, there's also...)
http://nsis.sourceforge.net/Repair_path_names_with_../
Quite right, though, that you need to do something of the sort if the path is relative or leads to to a file or folder that doesn't (yet) exist.
If the path is relative, GetFullPathName before hand should sort that out I think.
Stu
Stu
Originally posted by Afrow UKYes, of course ...
If the path is relative, GetFullPathName before hand should sort that out I think.
Sorry, there was a typo/thinko back there. I meant to write:
...you need to do something of the sort if the path is relative and leads to to a file or folder that doesn't (yet) exist.
GetFullPathname doesn't work on non-existent files (unfortunately).
Right so how about making that folder with the relative path, use GetFullPathName then perhaps remove it (if necessary).
Stu
Stu
Thanks everyone, very helpful.