I want to do the same thing as the bash dirname
command or python os.path.split()[0]
in vimscript for any path string (not necessarily the path of the current file).
Sample desired behaviour:
/a/b/
->/a
/a/b
->/a
I have tried fnamemodify()
but to me its output seems to depend on whether dirs exist or not:
:ec fnamemodify( '/usr/idontexist', ':p:h')
gives:
/usr
which is good, but:
:ec fnamemodify( '/usr/bin', ':p:h')
gives:
/usr/bin
which is not what I want, and I can't figure out what it is doing.
I hope to find a cross platform solution.