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);
# fileparse should returns file, directory and suffix. ($filename, $dir, $suffix) = fileparse (c:\test\abc\what\somefile.txt);
Check perldocs for details.
HTH Babs
Ben Crane wrote:
Hi all,
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...
e.g: foreach $line (@Path_Filename) { chomp($line); (@Path_Breakdown) = split(/(\w+\W)(\w+\W)/, $line); }
but my biggest problem is how to match a word character \w then match everything until the last \...that will comprise of the file path and the final \ onwards will be the filename incl. or excl. the file extension...
I've tried to get the pattern matching to include everything including the \ but it doesn't seem to work. The closest I've gotten is:
c:\test\abc\what\somefile.txt c: \test\abc\what\ somefile. txt
Any ideas? Is there a pattern character that I'm missing here that allows you to match a certain character and then stop if it's the last one of it's type?
Ben
__________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>