Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Dissecting a complete pathname to a file

by mreece (Friar)
on Feb 27, 2007 at 22:51 UTC ( #602403=note: print w/replies, xml ) Need Help??


in reply to Dissecting a complete pathname to a file

consider:
use File::Spec; my ($vol, $path, $file) = File::Spec->splitpath( File::Spec->rel2abs($filespec) );
(rel2abs uses Cwd::cwd in this case)

Replies are listed 'Best First'.
Re^2: Dissecting a complete pathname to a file
by ikegami (Pope) on Feb 27, 2007 at 23:53 UTC

    Not quite there. Then you have to join $vol and $path together, and File::Spec doesn't provide the means to do that. You might say "But catpath!", but using catpath without a file name is undocumented, and it leaves an errant trailing slash on my system. Rather than using the fragile

    use File::Spec::Functions qw( splitpath catpath rel2abs canonpath ); my ($v, $p, $file_name) = splitpath(rel2abs($file_path)); my $dir_path = canonpath(catpath($v, $p));

    use the module designed for the task at hand, File::Basename.

    use File::Basename qw( fileparse ); use File::Spec::Functions qw( rel2abs ); my ($file_name, $dir_path) = fileparse(rel2abs($file_path));

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://602403]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2021-02-25 02:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?