home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / File::Basename.z / File::Basename
Encoding:
Text File  |  1998-10-30  |  6.7 KB  |  199 lines

  1.  
  2.  
  3.  
  4. FFFFiiiilllleeee::::::::BBBBaaaasssseeeennnnaaaammmmeeee((((3333))))                                            FFFFiiiilllleeee::::::::BBBBaaaasssseeeennnnaaaammmmeeee((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      fileparse - split a pathname into pieces
  10.  
  11.      basename - extract just the filename from a path
  12.  
  13.      dirname - extract just the directory from a path
  14.  
  15. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  16.          use File::Basename;
  17.  
  18.          ($name,$path,$suffix) = fileparse($fullname,@suffixlist)
  19.          fileparse_set_fstype($os_string);
  20.          $basename = basename($fullname,@suffixlist);
  21.          $dirname = dirname($fullname);
  22.  
  23.          ($name,$path,$suffix) = fileparse("lib/File/Basename.pm","\.pm");
  24.          fileparse_set_fstype("VMS");
  25.          $basename = basename("lib/File/Basename.pm",".pm");
  26.          $dirname = dirname("lib/File/Basename.pm");
  27.  
  28.  
  29. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  30.      These routines allow you to parse file specifications into useful pieces
  31.      using the syntax of different operating systems.
  32.  
  33.      fileparse_set_fstype
  34.          You select the syntax via the routine _f_i_l_e_p_a_r_s_e__s_e_t__f_s_t_y_p_e().
  35.  
  36.          If the argument passed to it contains one of the substrings "VMS",
  37.          "MSDOS", "MacOS", "AmigaOS" or "MSWin32", the file specification
  38.          syntax of that operating system is used in future calls to
  39.          _f_i_l_e_p_a_r_s_e(), _b_a_s_e_n_a_m_e(), and _d_i_r_n_a_m_e().  If it contains none of these
  40.          substrings, UNIX syntax is used.  This pattern matching is case-
  41.          insensitive.  If you've selected VMS syntax, and the file
  42.          specification you pass to one of these routines contains a "/", they
  43.          assume you are using UNIX emulation and apply the UNIX syntax rules
  44.          instead, for that function call only.
  45.  
  46.          If the argument passed to it contains one of the substrings "VMS",
  47.          "MSDOS", "MacOS", "AmigaOS", "os2", "MSWin32" or "RISCOS", then the
  48.          pattern matching for suffix removal is performed without regard for
  49.          case, since those systems are not case-sensitive when opening
  50.          existing files (though some of them preserve case on file creation).
  51.  
  52.          If you haven't called _f_i_l_e_p_a_r_s_e__s_e_t__f_s_t_y_p_e(), the syntax is chosen by
  53.          examining the builtin variable $^O according to these rules.
  54.  
  55.      fileparse
  56.          The _f_i_l_e_p_a_r_s_e() routine divides a file specification into three
  57.          parts: a leading ppppaaaatttthhhh, a file nnnnaaaammmmeeee, and a ssssuuuuffffffffiiiixxxx.  The ppppaaaatttthhhh contains
  58.          everything up to and including the last directory separator in the
  59.          input file specification.  The remainder of the input file
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. FFFFiiiilllleeee::::::::BBBBaaaasssseeeennnnaaaammmmeeee((((3333))))                                            FFFFiiiilllleeee::::::::BBBBaaaasssseeeennnnaaaammmmeeee((((3333))))
  71.  
  72.  
  73.  
  74.          specification is then divided into nnnnaaaammmmeeee and ssssuuuuffffffffiiiixxxx based on the
  75.          optional patterns you specify in @suffixlist.  Each element of this
  76.          list is interpreted as a regular expression, and is matched against
  77.          the end of nnnnaaaammmmeeee.  If this succeeds, the matching portion of nnnnaaaammmmeeee is
  78.          removed and prepended to ssssuuuuffffffffiiiixxxx.  By proper use of @suffixlist, you
  79.          can remove file types or versions for examination.
  80.  
  81.          You are guaranteed that if you concatenate ppppaaaatttthhhh, nnnnaaaammmmeeee, and ssssuuuuffffffffiiiixxxx
  82.          together in that order, the result will denote the same file as the
  83.          input file specification.
  84.  
  85. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  86.      Using UNIX file syntax:
  87.  
  88.          ($base,$path,$type) = fileparse('/virgil/aeneid/draft.book7',
  89.                                          '\.book\d+');
  90.  
  91.      would yield
  92.  
  93.          $base eq 'draft'
  94.          $path eq '/virgil/aeneid/',
  95.          $type eq '.book7'
  96.  
  97.      Similarly, using VMS syntax:
  98.  
  99.          ($name,$dir,$type) = fileparse('Doc_Root:[Help]Rhetoric.Rnh',
  100.                                         '\..*');
  101.  
  102.      would yield
  103.  
  104.          $name eq 'Rhetoric'
  105.          $dir  eq 'Doc_Root:[Help]'
  106.          $type eq '.Rnh'
  107.  
  108.  
  109.      basename
  110.           The _b_a_s_e_n_a_m_e() routine returns the first element of the list
  111.           produced by calling _f_i_l_e_p_a_r_s_e() with the same arguments, except that
  112.           it always quotes metacharacters in the given suffixes.  It is
  113.           provided for programmer compatibility with the UNIX shell command
  114.           _b_a_s_e_n_a_m_e(1).
  115.  
  116.      dirname
  117.           The _d_i_r_n_a_m_e() routine returns the directory portion of the input
  118.           file specification.  When using VMS or MacOS syntax, this is
  119.           identical to the second element of the list produced by calling
  120.           _f_i_l_e_p_a_r_s_e() with the same input file specification.  (Under VMS, if
  121.           there is no directory information in the input file specification,
  122.           then the current default device and directory are returned.)  When
  123.           using UNIX or MSDOS syntax, the return value conforms to the
  124.           behavior of the UNIX shell command _d_i_r_n_a_m_e(1).  This is usually the
  125.           same as the behavior of _f_i_l_e_p_a_r_s_e(), but differs in some cases.  For
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. FFFFiiiilllleeee::::::::BBBBaaaasssseeeennnnaaaammmmeeee((((3333))))                                            FFFFiiiilllleeee::::::::BBBBaaaasssseeeennnnaaaammmmeeee((((3333))))
  137.  
  138.  
  139.  
  140.           example, for the input file specification _l_i_b/, _f_i_l_e_p_a_r_s_e()
  141.           considers the directory name to be _l_i_b/, while _d_i_r_n_a_m_e() considers
  142.           the directory name to be .).
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.