How to check if a path *could* be a legal path?
lbates at swamisoft.com
Tue Apr 20 16:07:51 CEST 2004
It is much easier to put your code that would create the
path inside a try block and just have an exception that
handles the failure. If most of the time the path is
legal, it is faster also.
"Maciej Sobczak" <no.spam at no.spam.com> wrote in message
news:c62ums$b3b$1 at atlantis.news.tpi.pl...
> 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.
> s = 'C:\file.txt'
> the above is potentially a valid path on my system.
> 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?
> Maciej Sobczak : http://www.msobczak.com/
> Programming : http://www.msobczak.com/prog/
More information about the Python-list