How to check if a path *could* be a legal path?

Gerrit gerrit at nl.linux.org
Tue Apr 20 07:03:43 EDT 2004


Maciej Sobczak wrote:
> 1.
> s = 'C:\file.txt'
> 
> the above is potentially a valid path on my system.
> 
> 2.
> s = 'cc:/^- =#jk\kj+.+?! :-)'
> 
> the above is rather invalid and I would like to check it somehow before 
> I even try to create the file.
> 
> Does the Python library contain a functionality that allows to achieve 
> this goal?

No.
It's different on different platforms.
On Unix, for example, everything without \0 (ascii 0) is legal.
I don't know the rules Windows needs, but apparantly they are more
strict, or else the second path would be potentially valid as well.

There may be a 3rd party package that has this functionality, however,
or something in a windows-specific package.

Can't you pass it to exists? Maybe os.path.exists makes a different
between ENOENT and invalid paths...

Gerrit.

-- 
Weather in Twenthe, Netherlands 20/04 12:25:
	12.0°C Scattered clouds partly cloudy wind 4.0 m/s SSW (57 m above NAP)
-- 
Experiences with Asperger's Syndrome:
	EN http://topjaklont.student.utwente.nl/english/
	NL http://topjaklont.student.utwente.nl/




More information about the Python-list mailing list