encode short string as filename (unix/windows)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robert

    #1

    encode short string as filename (unix/windows)

    want to encode/decode an arbitrary short 8-bit string as save filename.
    is there a good already builtin encoding to do this (without too much
    inflation) ? or re.sub expression?

    or which characters are not allowed in filenames on typical OS?

    robert
  • Grant Edwards

    #2
    Re: encode short string as filename (unix/windows)

    On 2006-03-27, robert <no-spam@no-spam-no-spam.com> wrote:[color=blue]
    > want to encode/decode an arbitrary short 8-bit string as save filename.
    > is there a good already builtin encoding to do this (without too much
    > inflation) ? or re.sub expression?
    >
    > or which characters are not allowed in filenames on typical OS?[/color]

    Under unix, "/" and NULL aer not allowed.

    There are other characters that are not recommended, but those
    are the only two that are not allowed.

    --
    Grant Edwards grante Yow! .. the MYSTERIANS are
    at in here with my CORDUROY
    visi.com SOAP DISH!!

    Comment

    • nikie

      #3
      Re: encode short string as filename (unix/windows)

      > want to encode/decode an arbitrary short 8-bit string as save filename.[color=blue]
      > is there a good already builtin encoding to do this (without too much
      > inflation) ? or re.sub expression?
      >
      > or which characters are not allowed in filenames on typical OS?[/color]

      On Windows, / \ : * ? " < > | are forbidden, and the name can't be
      empty.

      Using urlsafe_b64enco de/...decode should work on any platform.

      Comment

      • Diez B. Roggisch

        #4
        Re: encode short string as filename (unix/windows)

        robert wrote:
        [color=blue]
        > want to encode/decode an arbitrary short 8-bit string as save filename.
        > is there a good already builtin encoding to do this (without too much
        > inflation) ? or re.sub expression?[/color]

        Yuu could use the base64-encoder. Disadvantage is clearly that you can't
        easily read your original text. Alternatively, three is that encoding that
        is used by e.g. emails if you have an umlaut in a name. I _think_ it is
        called puny-code, but I'm not sure how and if you can use that from within
        python - google yourself :)

        diez

        Comment

        • Steven D'Aprano

          #5
          Re: encode short string as filename (unix/windows)

          On Mon, 27 Mar 2006 08:14:07 -0800, nikie wrote:
          [color=blue][color=green]
          >> want to encode/decode an arbitrary short 8-bit string as save filename.
          >> is there a good already builtin encoding to do this (without too much
          >> inflation) ? or re.sub expression?
          >>
          >> or which characters are not allowed in filenames on typical OS?[/color]
          >
          > On Windows, / \ : * ? " < > | are forbidden, and the name can't be
          > empty.[/color]

          Windows also has a number of "reserved names" that you can't use. However,
          in general, it is best to ignore that and just let Windows raise an error
          if it chooses. But for completeness, here is the the canonical list of
          prohibited file names and characters for Windows:

          http://msdn.microsoft.com/library/de...ing_a_file.asp

          or http://makeashorterlink.com/?I2B853DDC



          --
          Steven.

          Comment

          • robert

            #6
            Re: encode short string as filename (unix/windows)

            Steven D'Aprano wrote:
            [color=blue]
            > On Mon, 27 Mar 2006 08:14:07 -0800, nikie wrote:
            >
            >[color=green][color=darkred]
            >>>want to encode/decode an arbitrary short 8-bit string as save filename.
            >>>is there a good already builtin encoding to do this (without too much
            >>>inflation) ? or re.sub expression?
            >>>
            >>>or which characters are not allowed in filenames on typical OS?[/color]
            >>
            >>On Windows, / \ : * ? " < > | are forbidden, and the name can't be
            >>empty.[/color]
            >
            >
            > Windows also has a number of "reserved names" that you can't use. However,
            > in general, it is best to ignore that and just let Windows raise an error
            > if it chooses. But for completeness, here is the the canonical list of
            > prohibited file names and characters for Windows:
            >
            > http://msdn.microsoft.com/library/de...ing_a_file.asp
            >
            > or http://makeashorterlink.com/?I2B853DDC
            >[/color]

            thanks. infact to avoid COMx etc. I have also to prepend and remove a
            char like _ on encode/decode in addition to what I just posted

            Robert

            Comment

            Working...