KW.pm Only the Lonely #10

File::Spec::Functions

  • File::Spec - portably perform operations on file names

               use File::Spec;
               my ($volume, $dir_path, $file) = File::Spec->splitpath( $path );
               $dir_path = File::Spec->canonpath( $dir_path );
  • A function interface might be easier to use:

  • File::Spec::Functions

          use File::Spec::Functions qw[splitpath canonpath splitdir abs2rel];
          # split a path into logical pieces
          my ($volume, $dir_path, $file) = splitpath( $path );
          # clean up directory path
          $dir_path = canonpath $dir_path;
          # split the directories into a list
          my @dirs = splitdir $dir_path;
          # turn the full path into a relative path
          my $rel_path = abs2rel $path;

<< Previous | Index | Next >> Copyright © 2005 Daniel Allen