Somebody I know expressed irritation today regarding those of us who tend not to use spaces in our filenames, e.g. NamingThingsLikeThis.txt -- despite most modern operating systems supporting spaces in filenames. Non-technical people must look at filenames created by geeks and wonder where we learned English.

So, what are the reasons that spaces in filenames are avoided or discouraged?

The most obvious reason I could think of, and why I typically avoid it, are the extra quotes required on the command line when dealing with such files.

Are there any other significant reasons, other than the practice being a vestigial preference?


UPDATE: Thanks for all your answers! I'm surprised how popular this was. So, here's a summary:


Six Reasons Why Geeks Prefer Filenames Without Spaces In Them

  1. It's irritating to put quotes around them when referenced on the command line (or elsewhere.)
  2. Some older operating systems didn't used to support them and us old dogs are used to that.
  3. Some tools still don't support spaces in filenames at all or very well. (But they should.)
  4. It's irritating to escape spaces when used where spaces must be escaped, such as URLs.
  5. Certain unenlightened services (e.g. file hosting, webmail) remove or replace spaces anyway!
  6. Names without spaces can be shorter, which is sometimes desirable as paths are limited.


link|improve this question

2  
I had the same doubt today, wondered if I should ask it in SO or here, did a google before asking and landed here.. Thank you for asking and thanks Jeff and Co. for the wonderful sites! – Amarghosh Nov 18 '10 at 12:37
feedback

12 Answers

up vote 39 down vote accepted

Whitespace characters in filenames can be a right royal pain in the proverbial in many contexts on the command line, and in scripts, where you have to be careful to make sure they are properly escaped so don't look like separators to the commands you are running.

It is just safer not to have them there, even if you are sure the file/dir/what-ever is never going to be used in such a context.

That, and old habits die hard.

link|improve this answer
They're also a right royal pain to deal with then you have to compose paths and modify them. Making sure that the components are unquoted and unescaped for modification before re-escaping/re-quoting, especially if pieces get sent off to other bits of code to be manipulated. – afrazier Mar 16 '11 at 18:35
feedback

In addition to the other answers about command line and old habits, there are also many network protocols which require special care when dealing with filenames containing spaces.

(If you've ever tried to download "Product List.pdf" from a website, and ended up with a file just called "Product", you got bitten by this, because the programmer on the other end didn't know or couldn't figure out the quoting rules for the http Content-Disposition header.)

link|improve this answer
3  
+1. HTTP for a start. Spaces in URLs (for any protocol, not just HTTP) should be escaped out to %20 or +. Confusion can arise when they are not encoded as the should be. For web pages there is a visual reason to avoid both spaces and the underscore ("_") commonly used to replace them - they may both look the same in an underlined link, so someone copying the link manually or reading it to someone may get it wrong. – David Spillett Aug 25 '09 at 13:04
1  
One of the most annoying things about spaces needing to be encoded in URLs is the tendancy for certain software to end up keeping the spaces encoded ... – SamB May 29 '10 at 17:05
feedback

I do it because spaces become %20's in file names on the web, which makes it harder to manage my site's assets. Image 1.png and Image%201.png is comfusing. It's easier to use Image001.png. This really falls under the same category as escape sequences for command line.

link|improve this answer
+1 for another specific example. I hate looking at URLs with excessive escaping as well. – Chris W. Rea Aug 25 '09 at 11:58
feedback

So, what are the reasons that spaces in filenames are avoided or discouraged?

  1. old habits die hard :)

  2. some file and image hosting services change the filemanes if spaces are involved.

link|improve this answer
feedback

I do it for elbow-case avoidance. I know this_will_work.txt will work in all cases. I would just rather not deal with the small percentage of cases/applications that don't work with spaces in a file name; especially when I'm sending a file to someone else.

link|improve this answer
3  
Epic file send! Especially? – tsilb Aug 25 '09 at 1:05
@tsilb: rofl, epic failure of file send. Fixed, thank you. :) – JP. Aug 25 '09 at 1:16
feedback

I avoid spaces for files that are part of the software I work on, because handling spaces with GNU Make is a pain.

link|improve this answer
1  
+1 for a concrete example of the pain. – Chris W. Rea Aug 25 '09 at 11:52
feedback

e.g. NamingThingsLikeThis.txt

Like already mentioned, old habits die hard.

The example you have given is a perfect proof of it: The file could actually have the extension "Text", that is, "NamingThingsLikeThis.text".

link|improve this answer
feedback

It's nice to be able to type filenames without having to worry about quoting or escaping. (Then again, I have some files named ?????.)

Also, bash sucks with spaces inside parameters.

But ultimately, I suppose it's because I'm a programmer. Files containing works with formal titles, like videos or music or ebooks, are spaced and capitalized correctly. But mere identifiers are written how I write any identifier: foo-bar-baz.

link|improve this answer
feedback

I agree that old habits are the reason.

This discussion leads me to think that the best reason to kill this old habit is to improve my code. Non-programmers will use spaces in their file names. If my code misbehaves because it isn't expecting a space, then it's my fault -- not the fault of the user.

Any programmer's first tendency is to test with his or her standard behavior. If my filenames don't contain spaces, I'm not testing well.

link|improve this answer
1  
And that kind of reasoning, "let's just make one big general case", without thinking of what should be allowed and what shouldn't, is one of the main reasons why programs that required 1Mb in the early 90ties now require 500Mb, but still they do the same thing. – ldigas Aug 25 '09 at 1:49
@Idigas: They still do that thing? Things are better than I thought! – SamB May 29 '10 at 17:27
feedback

Sometimes, spaces can present a problem when dealing on the command line, or when using older OS's, or when writing programs which will be compiled on different OS's, or when ... there are many reasons which can present problematic, and I don't really feel it is such a trouble to write the file as: file-without-blanks.txt or *file_without_blanks.txt*. I prefer the dask because the underscore can sometimes become invisible when dealing with, for example, underlined font.

But mostly, it is a matter of habit from the old age. Which I don't feel there are enough pro reasons to abandon.


An additional note, possibly not related, but nevertheless I'll put it here. People who name their files with spaces usually do not think much of that; the ones who don't often know a little of why it is good to avoid them in filenames.
And, we can all agree, there is nothing worse than a file which is names "Dear Sir or Madam, I'm writing you this letter to inform you of yo.doc".

Not just spaces - file length also counts for something, and IMHO, it should not be longer than, let's say, 30 characters. For long file names with spaces inside are also a blessing when recording CD's, DVD's and such which need to be read under older OS's, and in between Win and *nix plaforms.

link|improve this answer
Lazy Word users ... – SamB Jan 28 at 1:46
feedback

I use spaces in filenames, when it seems logical. Readability is priority. Software, which does not work correctly with such filenames, is moved to trash :)

link|improve this answer
2  
Readability is a very good point, but it's just so hard to throw HTTP in the trash. I've tried, but it just keeps popping right back back! :) – Ilari Kajaste Sep 17 '09 at 6:56
This is the correct answer. :) Computers exist to serve humans, not the other way around. – endolith Jan 12 '10 at 22:27
feedback

Like you said, they are a lot easier to deal with on the command line. And for programming is I am not sure if it is even possible or feasible to use spaces in filenames.

link|improve this answer
1  
Could you elaborate? In what context are spaces problematic when programming? Of course we need to make sure our programs can handle spaces if people do choose to use them :-) – Chris W. Rea Aug 25 '09 at 0:58
2  
@cwrea - many people use many programming languages, and many languages means even more compilers. Some of them are old (for whatever reasons people use them). Not all of them handle spaces in the same way - let's just say that that fact alone is enough reason for avoiding them. – ldigas Aug 25 '09 at 1:08
3  
So just to be clear: we're referring to spaces in the source code filenames processed by some compilers as being potentially problematic. We're not saying those languages/compilers don't let us develop programs that can handle spaces in filenames, correct? – Chris W. Rea Aug 25 '09 at 11:57
feedback

protected by studiohack Mar 16 '11 at 16:36

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.