For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2007 > Extracting file name from full name









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Extracting file name from full name
andrewmchorney@cox.net

2007-09-27, 7:01 pm

Hello

I have a string that contains a full path and file name. What is the easiest way to extract the file name? For example the path is /dir1/dir2/dir3/file.txt.

Andrew
John W. Krahn

2007-09-27, 7:01 pm

andrewmchorney@cox.net wrote:
> Hello


Hello,

> I have a string that contains a full path and file name. What is
> the easiest way to extract the file name? For example the path is
> /dir1/dir2/dir3/file.txt.


$ perl -le'

use File::Basename;

my $full_path = q[/dir1/dir2/dir3/file.txt];

my $file_name = basename $full_path;

print $file_name;

'
file.txt



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com