In a Python script I want to know which characters are inapplicable for use in file names under current OS/FileSystem. I'd like to create files without errors. Is there such feature in Python?
Asked
Active
Viewed 169 times
0
-
4Are you aware that that list could be really long? On a FAT system, it would probably encompass >99% of Unicode. – phihag Oct 05 '11 at 22:56
-
Stick to ASCII, it's a safe bet on any current OS/fs. – 9000 Oct 05 '11 at 22:58
-
9000, how about "\/?" - they are ASCII, but still unwanted on FAT. – Pavel Vlasov Oct 05 '11 at 23:54
-
character don't get "[deprecated](http://en.wikipedia.org/wiki/Deprecated)" – Jochen Ritzel Oct 06 '11 at 00:21
-
the comments by @phihag and 9000 are on the right track: define or find a whitelist of characters: a subset of acceptable characters for you. That way, you cut down on processing, and you are sure of what you're going to get. – Adriano Varoli Piazza Oct 06 '11 at 01:02
-
@9000 unless the OS uses EBCDIC. Could happen. Still, most programs will have worse problems in an environment like that. – Adriano Varoli Piazza Oct 06 '11 at 13:02
1 Answers
0
I hate to answer a question with another question, but this question seems to be what you are looking for: turn a string into a valid filename in Python. Otherwise, the list of reserved characters by OS is here.

Community
- 1
- 1

Adriano Varoli Piazza
- 7,297
- 5
- 39
- 50