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

From: Maciej Sobczak (no.spam_at_no.spam.com)
Date: 04/20/04


Date: Tue, 20 Apr 2004 12:40:04 +0200

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?

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/


Relevant Pages

  • Re: Valid File Path Format
    ... > How do you check a value to see if it is in a valid file ... > Todd Huttenstine ... Dim x As String ... Another useful link is: http://www.primeconsulting.com/faqs/faq2000.html ...
    (microsoft.public.excel.programming)
  • Re: Hmm......
    ... I have a string with me and I want to know if it represents a valid file name or a directory name. ... Hoever, even before that, I need to validate that string by assertig that this given damn string is indeed a potentially valid one. ... Different filesystems have different rules, and what's valid in one filesystem may not be valid in another. ... There's no single set of rules that can be applied to a string to inform you whether it's a valid path. ...
    (microsoft.public.dotnet.languages.csharp)
  • Valid file name
    ... Is there a simple function to test if a string is a valid file name (i.e does not contain illegal characters etc) other than doing it the long way? ... Jack Russell ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Save in location button
    ... A slash is not a valid file name character. ... date string with something like this: ... Jim Rech ...
    (microsoft.public.excel)
  • Re: Save in location button
    ... A slash is not a valid file name character. ... date string with something like this: ... Jim Rech ...
    (microsoft.public.excel.programming)

Loading