in reply to Re: Path strings
in thread Path strings

When I use File::Spec->splitpath() the final directory is seen as a file unless it has a trailing delimiter, in which case it is seen as part of the directory. Also the doc on the module states "The directory portion may or may not be returned with a trailing '/'".

When I use File::Basename->parsefile() the final directory is seen as a suffix unless it has a trailing delimiter, in which case it is seen as part of the directory.

Also when incorporating other peoples code, this situation crops up.

When I say "massage", I mean I must add and remove the delimiters from the strings to split them, join them, pass them on etc.

Replies are listed 'Best First'.
Re^3: Path strings
by bobf (Monsignor) on Jan 27, 2007 at 05:13 UTC

    If you're using splitpath to split a path that ends in a directory rather than a file, then you should be using splitdir instead*. That may solve your trailing '/' issue.

    I don't think I've ever had to manually add or remove delimiters from paths (with or without filenames) when using File::Spec. If you have specific examples that cause you to jump through hoops, please post them. I'm sure the monks around here will provide several approaches to solving the problem. :-)

    *Update: You could use splitpath, but you would need to set the second param to true (or, as you found, add a trailing directory separator). See the docs for more info.