Get path from filename

Mar 20, 2005 5 Replies

What's the easiest way to get the path from a fully pathed filename? For instance, given



C:\Some Directory\And Another Directory\My Word Document.doc



I'd like (with or without the trailing slash)



C:\Some Directory\And Another Directory\



Doh! Posted to the wrong group. :)

Well, if reading it isn't good enough...how about "cd" ?

You could buy MKS toolkit or download cygwin for free. It's tricky to get cygwin installed, though. Both of these should come with "basename" and "dirname" programs which do what you want.

But both of those are overkill. If you can program, look up the basename and dirname functions and try to write them yourself.

Doh! Wrong group! :-) Oh well, you got an answer anyway.

Go to the Microsoft web site and download Windows Services for Unix and then use the basename utility. MS used to charge $99 for the package, but now it is free.

% echo `pwd`"/filename"

florian

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required