Re: Extracting file name from full name



andrewmchorney@xxxxxxx 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
.



Relevant Pages

  • Re: adding a word at the end of each line
    ... Perl isn't a toolbox, but a small machine shop where you ... can special-order certain sorts of tools at low cost and ...
    (comp.unix.shell)
  • Re: how do check th argument is passing to running file
    ... sivasakthi wrote: ... Perl isn't a toolbox, but a small machine shop where you ... can special-order certain sorts of tools at low cost and ...
    (perl.beginners)
  • ANNOUNCE: Archive::Zip 1.13 released
    ... don't use Perl any more, ... files), extract a file, and then re-write the zip, you will get a ... Members can be created from members in existing ... - FAQ NAME fix from Michael Schwern ...
    (comp.lang.perl.modules)
  • RE: Optimization for faster select...
    ... Although its a cute idea to create a function based index on SUBSTR ... I tried to see whether the SUBSTR could be replaced with Perl formatting ... the possibility of writes delaying the extract. ... So, ladies and gets, everything comes down to using RowCacheSize attribute. ...
    (perl.dbi.users)
  • Re: Extracting Text
    ... >> recommended to extract text from a text file and placed into a ... I think gawk or awk would be the best thing for the OP to use too. ... editors such as Perl or Emacs Lisp. ...
    (comp.programming)