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

Bill Rubenstein wsr2 at swbell.net
Tue Apr 20 18:24:31 EDT 2004


What is the problem with just creating the file and handling the error case with an except 
clause?

Bill

In article <c62ums$b3b$1 at atlantis.news.tpi.pl>, no.spam at no.spam.com says...
> Hi,
> 
> I have a string.
> This string is to be used as a path for a new file.
> I would like to check if this string *could be* a valid file name, 
> *before* I try to create the file itself.
> In other words, I would like to know whether some string violates the 
> underlying OS's policies (or maybe some more restriced policies, but 
> portable) considering file paths.
> 
> Example:
> 
> 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?
> 
> 



More information about the Python-list mailing list