[tpm] splitting filespecs

rob at cryptic.org rob at cryptic.org
Thu May 10 10:30:43 PDT 2012

 Further to that, "." actually is a special-case directory, similar to 
 "..". Like a double period is "parent directory", a single period is 
 "current directory". It's like this on both Unix and Windows (and 
 presumably Mac).

 On Thu, 10 May 2012 12:18:44 -0400, Stuart Watt wrote:
> I've used File::Spec reliably for this, but it's right to claim that
> "." in "/." isn't a filename. It isn't really. I believe it is a
> special case used by UNIX to inform it that the thing specified is to
> be interpreted as a directory. So, for example, "/usr/x" could be a
> *file* named "x" (, but "/usr/x/." is specifically a directory. It's
> useful when it could be either and when it doesn't yet exist. This
> special case logic is built into File::Spec.
> You should *always* be able to split things with
> File::Spec->splitpath/splitdir and rejoin with
> File::Spec->catpath/catdir, and I've always found it works well for
> both UNIX and for Windows.
> All the best
> Stuart
> On 2012-05-10, at 11:59 AM, Fulko Hew wrote:
>> I'm looking for a good library to split a filespec into directory
>> and filename components; so I can:
>> a) add a default dirspec if one wasn't provided
>> b) add a default filename if one wasn't provided
>> c) create the required directory path if it didn't already exist
>> So far I've tried
>> File::Basename and File::Spec
>> Unfortunately they both mis-behave?
>> File::Basename always provides a dirspec even if the original string
>> didn't have one
>> (so I can't tell if I need to insert my default one...)
>> and File::Spec (as far as I'm concerned) incorrectly splits '/.'
>> into
>> the directory of '/.' with no file name. I would have expected the
>> directory to be '/' and the filename to be '.'.
>> Am I wrong?
>> Is there a better library?
>> [I suppose I could just take the filename from File::Spec and
>> manually
>> extract everything in front of it from the original string as the
>> directory
>> and simply _ignore_ what the module tells me.]
>> ... and yes, I will eventually also need to parse DOS filespecs.
>> _______________________________________________
>> toronto-pm mailing list
>> toronto-pm at pm.org [1]
>> http://mail.pm.org/mailman/listinfo/toronto-pm
> Links:
> ------
> [1] mailto:toronto-pm at pm.org

More information about the toronto-pm mailing list