up vote 1 down vote favorite
share [g+] share [fb]

This question isn't about a specific programming language, but more about general best practices.

What characters are best (greatest compatibility over programming languages, OSs, file systems, etc.) to separate words in filenames?

For example:

  • file.name.txt
  • file_name.txt
  • file-name.txt
  • FileName.txt
  • filename.txt
link|improve this question
file_name - Ruby , fileName - java , FileName - C# , file-name - CSS – Anantha Kumaran Mar 6 '10 at 7:47
How can you answer this, besides repeating your examples? Sounds like community wiki to me. – Dykam Mar 6 '10 at 7:47
@Anantha Kumaran, some would discuss that css name :P. – Dykam Mar 6 '10 at 7:47
It's usually best to avoid spaces in filenames - not so much because of the few utilities that can't cope as because it causes hassle even when using tools that can cope, but need quoting around parameters or whatever. It's not fatal, but life is that little bit easier if you avoid spaces. Not an answer because it wasn't one of your options anyway, but I think it's worth saying. – Steve314 Dec 5 '11 at 6:32
feedback

migrated from stackoverflow.com Mar 7 '10 at 11:15

This question came from our site for professional and enthusiast programmers.

5 Answers

Since some OSes are cases insensitive, and some older OSes may get confused by dashes, I recommend the underscore as the sanest way.

link|improve this answer
feedback

Well, obviously no characters, i.e. FileName.txt, will be the most portable option. Given the remaining options, I tend to go with underscores. They function visually as spaces and don't cause the problems that spaces do.

  • periods: get confused with extensions
  • minus signs: get confused, visually at least, on Unix-y systems with command-line options.
  • spaces: Some programs, scripts, and the like get confused and try to break the filename apart at spaces.
  • (others): Any character that ever requires escaping, i.e. File\*Name.txt, would be a bad choice as well.

My exception to the rule: In my daily use, I tend to use spaces in filenames that I know I'll only ever be using through GUI file browsers and with word processors and the like. Every modern app and OS handles spaces correctly and they are the natural language way to break up words. As_opposed_to_writing_like_this_which_no_one_does.

link|improve this answer
It's not obviously true: some systems are case insensitive. When you look at your name in all upper- or lower-case, will it still make sense? – Jay Bazuzi Aug 10 '10 at 17:32
If it is a web accessible file running on a unix/linux platform, you want all lowercase file names. – James Watt Aug 10 '10 at 18:22
@Jay: Good point. @James: URLs are supposed to be case-insensitive, I think, but I suppose it's up to the web server implementation. Either way, good points. – Harvey Aug 25 '10 at 16:19
1  
@Jay - how many truly ignore space? Windows, for example, remembers the case of filenames even though it considers names that differ only in case to be equivalent - you still get to see the case. That isn't intended to recommend FileNamesLikeThis, which I quite strongly dislike, and there can still be problems with tools that don't allow for all the subtle issues that can result. – Steve314 Dec 5 '11 at 6:40
@Jay: You are confusing "case-sensitive" and "case-preserving". All Windows and Unix filesystems are at least case-preserving (even FAT if long filenames are in use) -- that is, they store the name exactly as entered, even though they accept variations when opening it later. – grawity Dec 5 '11 at 7:52
feedback

You can use underscores for the same chunks, dashes to separate chunks and the dot strictly for extension. E.g.: <artist>-<album>-<song>.<extension>

The_Cure-Best_of_Cure-Friday_I_am_in_love.mp3

link|improve this answer
This is a brilliant idea. Thanks! – Christopher Albon Mar 6 '10 at 12:37
2  
You could've picked a better song though ;D The_Cure-The_Head_On_The_Door-Inbetween_Days.mp3 =] – Shevek Mar 7 '10 at 11:24
feedback

Underscores and lower case are preferable. However, at this juncture and in the year 2011, any OS or program that is "confused" by or does not permit spaces in file names is either in need of a major rewrite or complete abandonment. There is also Unix/Linux arrogance to consider.

link|improve this answer
feedback

Spaces are a big no-no, though people around me use them occasionally.

I tend to use extra stops/periods. Some software might confuse this with the final period indicating filetype but I've not had problems with this that I remember.

Underscore and dash I sometimes use too though both have slight disadvantages. I've had hassle with some tools and dashes in names in the past, but they were badly designed command line tools that I never used again anyway. Underscore can be confusing if they end up as hyperlinks on a page that someone prints and copies the URL from - the underscore merges in with the underline that is default for links so the reader doesn't know it isn't a space.

link|improve this answer
-1 for "big no-no" without any explanation at all. Major operating systems have supported spaces for many, many years. – grawity Dec 5 '11 at 7:50
feedback

Your Answer

 
or
required, but never shown