Re: Making a string, file-safe (file-encode??)



adamorn@xxxxxxxxx wrote:
I was wondering if there was a quick way to ensure that a filename is
a safe.

What I mean is that if I am creating a file from a string variable, I
want to ensure that the file will actually be able to be created. So
if it contains a "?", then clearly I would want to eliminate it.

I know that there is something like URL encode that encodes strings
for use in urls, but is there another function that works similarly
for strings for files that I want to create?

Thanks!
? is not invalid on all system, linux handles it perfectly. The characters that are invalid are system specific, and some systems don't have limitations at all.

The only portable way to handle this is to catch exceptions and report them to the user.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.



Relevant Pages

  • Re: Help required to read and print lines based on the type of first character
    ... In the above case, "accurate, unambigous and well-expressed specs" are almost pseudocode. ... print "an invalid line" ... I'd say that the most "tricky" part is c., since there's more than one possible solution, but since it's about strings, looking for what features Python strings has to offer, and trying them out in the interactive interpreter should solve the problem very quickly. ...
    (comp.lang.python)
  • Re: What is wrong with this BAT File?
    ... I Have a problem with this bat file the two strings with the ... also included the two "Invalid path"errors that they ... remove "nospam" in order to email me. ...
    (microsoft.public.windowsxp.general)
  • What is wrong with this BAT File?
    ... I Have a problem with this bat file the two strings with the ** don't work and I can't see what is wrong with them. ... I also included the two "Invalid path"errors that they produced. ... remove "nospam" in order to email me. ...
    (microsoft.public.windowsxp.general)
  • Re: Making a string, file-safe (file-encode??)
    ... I know that there is something like URLencodethat encodes strings ... is not invalid on all system, ... Daniel Pitts' Tech Blog: ...
    (comp.lang.java.programmer)
  • Making a string, file-safe (file-encode??)
    ... I was wondering if there was a quick way to ensure that a filename is ... a safe. ... I know that there is something like URL encode that encodes strings ...
    (comp.lang.java.programmer)