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



adamorn@xxxxxxxxx wrote:
On Jun 17, 3:13 pm, Daniel Pitts
<newsgroup.spamfil...@xxxxxxxxxxxxxxxxxxx> wrote:
adam...@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 afilefrom a string variable, I
want to ensure that thefilewill 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 URLencodethat 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/>


ah, but Im actually pulling the filename from a variable that the user
does not set...
Then make sure the variable is being set by something that doesn't add invalid characters. Details might help us better help you.


--
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: About createFile
    ... handle.But the Filename is displaying correctly.can any one ... TEXTshould be used to declare unicode strings inside your code. ... (the reply address of this message is invalid) ... (l'indirizzo di reply di questo messaggio non è ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Generics
    ... runtime using a single method? ... Daniel Pitts' Tech Blog: ... arrays, integers, integer arrays, booleans and strings. ...
    (comp.lang.java.programmer)