home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_c21165477bc6bd12f29dca38152c9f93
< prev
next >
Wrap
Text File
|
2000-03-23
|
7KB
|
151 lines
<HTML>
<HEAD>
<TITLE>fileparse - split a pathname into pieces</TITLE>
<LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> fileparse - split a pathname into pieces</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#examples">EXAMPLES</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>fileparse - split a pathname into pieces</P>
<P>basename - extract just the filename from a path</P>
<P>dirname - extract just the directory from a path</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
use File::Basename;</PRE>
<PRE>
($name,$path,$suffix) = fileparse($fullname,@suffixlist)
fileparse_set_fstype($os_string);
$basename = basename($fullname,@suffixlist);
$dirname = dirname($fullname);</PRE>
<PRE>
($name,$path,$suffix) = fileparse("lib/File/Basename.pm","\.pm");
fileparse_set_fstype("VMS");
$basename = basename("lib/File/Basename.pm",".pm");
$dirname = dirname("lib/File/Basename.pm");</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P>These routines allow you to parse file specifications into useful
pieces using the syntax of different operating systems.</P>
<DL>
<DT><STRONG><A NAME="item_fileparse_set_fstype">fileparse_set_fstype</A></STRONG><BR>
<DD>
You select the syntax via the routine fileparse_set_fstype().
<P>If the argument passed to it contains one of the substrings
``VMS'', ``MSDOS'', ``MacOS'', ``AmigaOS'' or ``MSWin32'', the file specification
syntax of that operating system is used in future calls to
fileparse(), basename(), and dirname(). If it contains none of
these substrings, Unix syntax is used. This pattern matching is
case-insensitive. If you've selected VMS syntax, and the file
specification you pass to one of these routines contains a ``/'',
they assume you are using Unix emulation and apply the Unix syntax
rules instead, for that function call only.</P>
<P>If the argument passed to it contains one of the substrings ``VMS'',
``MSDOS'', ``MacOS'', ``AmigaOS'', ``os2'', ``MSWin32'' or ``RISCOS'', then the pattern
matching for suffix removal is performed without regard for case,
since those systems are not case-sensitive when opening existing files
(though some of them preserve case on file creation).</P>
<P>If you haven't called fileparse_set_fstype(), the syntax is chosen
by examining the builtin variable <CODE>$^O</CODE> according to these rules.</P>
<P></P>
<DT><STRONG><A NAME="item_fileparse">fileparse</A></STRONG><BR>
<DD>
The <A HREF="#item_fileparse"><CODE>fileparse()</CODE></A> routine divides a file specification into three
parts: a leading <STRONG>path</STRONG>, a file <STRONG>name</STRONG>, and a <STRONG>suffix</STRONG>. The
<STRONG>path</STRONG> contains everything up to and including the last directory
separator in the input file specification. The remainder of the input
file specification is then divided into <STRONG>name</STRONG> and <STRONG>suffix</STRONG> based on
the optional patterns you specify in <CODE>@suffixlist</CODE>. Each element of
this list is interpreted as a regular expression, and is matched
against the end of <STRONG>name</STRONG>. If this succeeds, the matching portion of
<STRONG>name</STRONG> is removed and prepended to <STRONG>suffix</STRONG>. By proper use of
<CODE>@suffixlist</CODE>, you can remove file types or versions for examination.
<P>You are guaranteed that if you concatenate <STRONG>path</STRONG>, <STRONG>name</STRONG>, and
<STRONG>suffix</STRONG> together in that order, the result will denote the same
file as the input file specification.</P>
<P></P></DL>
<P>
<HR>
<H1><A NAME="examples">EXAMPLES</A></H1>
<P>Using Unix file syntax:</P>
<PRE>
($base,$path,$type) = fileparse('/virgil/aeneid/draft.book7',
'\.book\d+');</PRE>
<P>would yield</P>
<PRE>
$base eq 'draft'
$path eq '/virgil/aeneid/',
$type eq '.book7'</PRE>
<P>Similarly, using VMS syntax:</P>
<PRE>
($name,$dir,$type) = fileparse('Doc_Root:[Help]Rhetoric.Rnh',
'\..*');</PRE>
<P>would yield</P>
<PRE>
$name eq 'Rhetoric'
$dir eq 'Doc_Root:[Help]'
$type eq '.Rnh'</PRE>
<DL>
<DT><STRONG><A NAME="item_basename"><CODE>basename</CODE></A></STRONG><BR>
<DD>
The <A HREF="#item_basename"><CODE>basename()</CODE></A> routine returns the first element of the list produced
by calling <A HREF="#item_fileparse"><CODE>fileparse()</CODE></A> with the same arguments, except that it always
quotes metacharacters in the given suffixes. It is provided for
programmer compatibility with the Unix shell command basename(1).
<P></P>
<DT><STRONG><A NAME="item_dirname"><CODE>dirname</CODE></A></STRONG><BR>
<DD>
The <A HREF="#item_dirname"><CODE>dirname()</CODE></A> routine returns the directory portion of the input file
specification. When using VMS or MacOS syntax, this is identical to the
second element of the list produced by calling <A HREF="#item_fileparse"><CODE>fileparse()</CODE></A> with the same
input file specification. (Under VMS, if there is no directory information
in the input file specification, then the current default device and
directory are returned.) When using Unix or MSDOS syntax, the return
value conforms to the behavior of the Unix shell command dirname(1). This
is usually the same as the behavior of fileparse(), but differs in some
cases. For example, for the input file specification <EM>lib/</EM>, <A HREF="#item_fileparse"><CODE>fileparse()</CODE></A>
considers the directory name to be <EM>lib/</EM>, while <A HREF="#item_dirname"><CODE>dirname()</CODE></A> considers the
directory name to be <EM>.</EM>).
<P></P></DL>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> fileparse - split a pathname into pieces</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>