Re: HOWTO: break up a directory path name into components ...

2002-05-16 Thread Ron Grabowski

> I have a subroutine "splitFilename" that I wrote that does this for
> me.  It's been enhanced over time to include support for UNC, but this
> is the meat of that subroutine that handles directory/path/filename
> strings:

Not to be a wet blanket, but isn't File::Basename part of the core? I
looked in Basename.pm and file/directory name parsing has been somewhat
standardized in Perl since 1996.

> ($file_d, $file_p_tl, $file_p, $file_f, $file_e) = m#^[\\/][\\/]#
> ? m#^([\\/][\\/][^\\/]+[\\/]) (([\\/][^\\/]+)*[\\/]) (.*?)
> ((\.[^.]+)*)$#x
> : m#^([a-z]:) (([\\/][^\\/]+)*[\\/]) (.*?) ((\.[^.]+)*)$#ix;

Not having looked at that in too much detail, Basename.pm basically
gives this for Win32 systems:

 ($dirpath,$basename) = (/^(.*[:>\]])?(.*)/s)
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



RE: HOWTO: break up a directory path name into components ...

2002-05-16 Thread Simmons, Aaron
Title: RE: HOWTO: break up a directory path name into components ...





All,


I have a subroutine "splitFilename" that I wrote that does this for me.  It's been enhanced over time to include support for UNC, but this is the meat of that subroutine that handles directory/path/filename strings:


local($_) = $filename;
($file_d, $file_p_tl, $file_p, $file_f, $file_e) = m#^[\\/][\\/]#
    ? m#^([\\/][\\/][^\\/]+[\\/]) (([\\/][^\\/]+)*[\\/]) (.*?) ((\.[^.]+)*)$#x
    : m#^([a-z]:) (([\\/][^\\/]+)*[\\/]) (.*?) ((\.[^.]+)*)$#ix;


$file_e =~ s/^\.//;
__END__


The vars of interest are as follows:
$file_d    -- drive letter (with colon)
$file_p    -- path info (no trailing slash)
$file_p_tl -- path info (trailing slash)
$file_f    -- filename (not including dot or extension)
$file_e    -- extension


As I was testing these 5 lines, I realized the $file_f and $file_e doesn't work for a filename name with more then one period (.) in it!  But I will leave as an exercise for the reader!  :)

-Aaron


-Original Message-
From: Lawrence Lordanich (x11486) [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 14, 2002 9:17 PM
To: perl win32 users
Subject: HOWTO: break up a directory path name into components ...



If I have a directory: c:\component1\component2\component3
how do I get at component[i]? I know I have seen this somewhere in my
reading but cannot find it now that I want it. Want a portable answer
too.


Thanks,


Lawrence.




--
Lawrence Lordanich   Tel:   +1 858-651-1486
Qualcomm Inc. (E-140F) Fax:   +1 858-845-8222
4875 Eastgate Mall   Email:   [EMAIL PROTECTED]
San Diego, CA 92121-1978  TimeZone:  GMT-8 (PST)

--