Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to seperate directory and file

by Divakar (Sexton)
on Sep 14, 2012 at 07:10 UTC ( #993661=perlquestion: print w/ replies, xml ) Need Help??
Divakar has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

i have to split directory and file from below lines.

/vobs_ostore/osci/scripts/utils/ostore_release

from this i have to get like this.

$dir_name=/vobs_ostore/osci/scripts/utils/

$file_name=ostore_release.

i dont know how to split and get it.

any help please?

Thank you...

Comment on How to seperate directory and file
Select or Download Code
Re: How to seperate directory and file
by ramesh824 (Initiate) on Sep 14, 2012 at 07:18 UTC
    You can use basename and dirname functions from "File::Basename" CPAN module to achieve this.
Re: How to seperate directory and file
by kcott (Abbot) on Sep 14, 2012 at 07:41 UTC

    G'day Divakar,

    The built-in module File::Spec has a number of functions for manipulating pathnames: splitpath() would be the one to use here.

    -- Ken

Re: How to seperate directory and file
by Anonymous Monk on Sep 14, 2012 at 08:22 UTC
    $ perl -E " use Path::Class; my $path = file(q[/ro/sham/bo.foo]); say +$path->parent; say $path->basename; " \ro\sham bo.foo

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2014-12-19 15:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (85 votes), past polls