The best way to do it; is using the standard module File::Basename.
For instance
use File::Basename;
# This should return "somefile".
$file_name = basename (c:\test\abc\what\somefile.txt);
# This should also return "c:\test\abc\what\"
$dir_name = dir (c:\test\abc\what\somefile.txt);
# filepars
Yes! And use Basename too.
these will also give you the advantage of making your programs more
portable!
-Tom Kinzer
-Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 10, 2003 11:37 AM
To: [EMAIL PROTECTED]
Subject: Re: file path pattern
Ben Crane wrote:
>
> Hi all,
Hello,
> I'm trying to split apart a filepath...e.g:
> c:\test\abc\what\somefile.txt
> The length of the filepath will never be constant...
$ perl -le'
use File::Spec;
my $path = q[c:\test\abc\what\somefile.txt];
my ( $vol, $dir, $file ) = File::Spec->splitpath(
Ben -
You can use the File::Basename module for this:
Your program would be akin to:
foreach $line (@Path_Filename)
{
chomp($line);
$filename = basename($line); # gives you the filename with the
extension
$location = dirname($line); # gives you the location with no
trail