Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

File::Spec is the long-awaited standard method for doing common tasks with file names and paths (file specifications or file specs) in a way that is portable between different operating systems.

The Good

What it can do:

  • $cpath = File::Spec->canonpath( $path );
  • $dirpath = File::Spec->catdir( $dir1, $dir2, $dir3 );
  • $filepath = File::Spec->catfile( $dir1, $dir2, $dir3, $file );
  • $curdir= File::Spec->curdir();  # "." on Unix
  • $nul= File::Spec->devnull();    # "/dev/null" on Unix
  • $root= File::Spec->rootdir();   # "/" on Unix
  • $tmpdir= File::Spec->tmpdir();  # "/tmp" or $ENV{TMPDIR}, etc.
  • $updir= File::Spec->updir();    # ".." on Unix
  • @list= File::Spec->no_upwards( @list ); # Strips "." and ".."
  • $ignore= File::Spec->case_tolerant();      # Returns false under Unix
  • $abs= File::Spec->file_name_is_absolute($path);
  • @path= File::Spec->path();      # Returns $ENV{PATH} as an array.
  • ($volume,$dirs,$file)= File::Spec->splitpath( $path [, $no_file ] );
  • @dirs= File::Spec->splitdir( $dirs );
  • $path= File::Spec->catpath( $vol, $dirs, $file );
  • $relpath= File::Spec->abs2rel( $path [, $base ] );
  • $abspath= File::Spec->rel2abs( $path [, $base ] );

The Bad

The documentation isn't OS-independent so you have to read the documentation for each OS-specific component of File::Spec. Start with perldoc File::Spec then perldoc File::Spec::Unix (since that part of the module is the most complete).

Not all methods are available on all platforms.

This module isn't available for even slightly old versions of Perl. Until and unless that changes, you may want to back-port the functionality to older versions of Perl yourself so that your code will still port to different OSes.

The Ugly

Getting File::Spec functionality for old versions of Perl in a portable, robust manner. I hope to add more details on this later.

        - tye (but my friends call me "Tye")

In reply to File::Spec by tye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-18 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found