encode short string as filename (unix/windows)

Steven D'Aprano steve at REMOVETHIScyber.com.au
Mon Mar 27 18:47:28 CEST 2006


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



-- 
Steven.




More information about the Python-list mailing list