473,378 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
Mar 27 '06 #1
5 2641
On 2006-03-27, robert <no*****@no-spam-no-spam.com> 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?


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!!
Mar 27 '06 #2
> 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.

Mar 27 '06 #3
robert 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?


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
Mar 27 '06 #4
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/de...ing_a_file.asp

or http://makeashorterlink.com/?I2B853DDC

--
Steven.

Mar 27 '06 #5
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/de...ing_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

Mar 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Scott Matthews | last post by:
I've recently come upon an odd Javascript (and/or browser) behavior, and after hunting around the Web I still can't seem to find an answer. Specifically, I have noticed that the Javascript...
27
by: gmtonyhoyt | last post by:
I need assistance coming up with a clean way to handle filename extensions with my application. While I can come up with several ways of doing so on my own, I felt perhaps it would be worth...
5
by: Generic Usenet Account | last post by:
I have been to recreate a problem that I am having with strings with the trivial code snippet given below. In the trivial code example, I am reading five lines from a data file, each line having...
5
by: Angus | last post by:
Hello I am using ifstream to load the contents of a text file into a char* variable. I am allocating using new with the file size as amount to allocate. My problem is that the variable...
7
by: AMP | last post by:
Hello, I am trying to split a string at the newline and this doesnt work: String Channel = FileName.Split("\r"); What am I doing wrong? Thanks Mike
11
by: tech | last post by:
Hi, I need a function to specify a match pattern including using wildcard characters as below to find chars in a std::string. The match pattern can contain the wildcard characters "*" and "?",...
1
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
23
by: =?Utf-8?B?TWlrZTE5NDI=?= | last post by:
This is an example that is supposed to work in VB http://support.microsoft.com/kb/175512/en-us After spending a couple of hours downloading and installing VB Express 2008 after someone told me it...
3
by: Kai Apel | last post by:
Dear Newsgroup, My name is Kai from Germany and I`m trying to learn VB.Net. My first Project is a simple Form with a button, witch is starting the filedialog for multiselect file. All thats...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.