No validation routine for an os.path

Peter Hansen peter at engcorp.com
Mon Aug 16 21:50:30 EDT 2004


Edward Diener wrote:

> Try as I might I can not find a routine in os.path which validates whether
> or not a path is syntactically valid, either as a directory or as a file.
> This is surprising since, although I know this is OS dependent, Python has
> many other classes and functions which will work properly depending on what
> OS they are currently running under. Is there such a path validation routine
> in any of the libraries distributed with Python or in any other 3rd party
> Python libraries ?

I don't really think so, and the last time this sort of thing
was discussed, I believe the conclusion was that it's not
actually possible to do such a thing in all cases anyway,
unless you are willing to actually attempt to create the
file or directory during the validation.

One reason I recall being given is that even on a given OS, different
file systems may support different sets of characters for filenames.
For example, a CDROM might disallow certain characters which the
standard file system allows, or a networked device (e.g. NFS, or
Samba) might allow a wider range of possibilities than the permitted
names on a hard drive.

In the end, this is somewhat like validating email addresses.  Until
you actually try and succeed (or fail) to send the message, you cannot
verify whether an address is "valid" for many definitions of valid.

-Peter



More information about the Python-list mailing list