malxau/yori

YPATH.EXE additional switch to remove a trainling slash from the resulting path

Closed this issue · 2 comments

Hello!
I've just got an idea to make something easier with ypath.exe utility.
The reason is if we got something like:

ypath.exe -f $PATH$ "%variable_with_path_to_directory%\..\..\..\..\.."

The resulting path will not contain trailing slash only if it is not get to the root of the drive, so there maybe 2 results:

C:\foo

or

C:\

There many circumstances where this trailing slash should be avoided... I know that we may do something like that:

ypath.exe -f $PARENT$ "%variable_with_path_to_directory%\..\..\..\..\..\plusOneHeHeHe"

but honestly it is so weird to get to... or we may check the resulting path and remove the trailing slash on our own, but I just want to suggest, that adding one little switch could keep simple things simple... Or maybe you could advice me how to get rid of that root drive trailing slash junk at one command?

P.S. I have tried another thing:

ypath.exe -f $DRIVE$:$DIR$ "%variable_with_path_to_directory%\..\..\..\..\.."

and this seems pretty obvious but this will ruin the day if path to resolve is UNC-path

I pushed commit 51c2fd0 for this.

You probably already know this, but the behavior here has frustrated me before. The code that adds back the backslash for drive roots is a bit of an unnatural hack, but it happens because "C:" refers to "the current directory on drive C:" which is very different to the drive root. Ideally it'd be nice to always have a trailing slash, but ypath.exe doesn't know if it's talking about files or directories, might be describing objects that don't exist yet, and a trailing slash is illegal for a file. This feels like one case where scripting is hazardous in general and I don't see a good way to make resilient scripting natural.

Nice to hear! Thanks for all the support! Happy holidays!