encode short string as filename (unix/windows)

robert no-spam at no-spam-no-spam.com
Mon Mar 27 11:47:30 EST 2006


Steven D'Aprano wrote:

> On Mon, 27 Mar 2006 08:14:07 -0800, nikie wrote:
> 
> 
>>>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.
> 
> 
> 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




More information about the Python-list mailing list