[tpm] splitting filespecs

Stuart Watt stuart at morungos.com
Thu May 10 09:18:44 PDT 2012


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
> http://mail.pm.org/mailman/listinfo/toronto-pm

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20120510/92e1ae65/attachment.html>


More information about the toronto-pm mailing list