encode short string as filename (unix/windows)

R

robert

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
 
G

Grant Edwards

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?

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.
 
D

Diez B. Roggisch

robert said:
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?

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
 
N

nikie

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?

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

Using urlsafe_b64encode/...decode should work on any platform.
 
S

Steven D'Aprano

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

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/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp

or http://makeashorterlink.com/?I2B853DDC
 
R

robert

Steven said:
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/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp

or http://makeashorterlink.com/?I2B853DDC

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
 
D

Dennis Lee Bieber

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 :)
Hmmm, passes newlines...

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,291
Messages
2,571,453
Members
48,135
Latest member
papaoso

Latest Threads

Top