Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

In an introductory GIS course, it was insisted that all spaces within file and folder names be replaced with underscores. Why is this taught? Is there a clear benefit of doing so?

share|improve this question
2  
The advice should not be limited to spaces! For insight, consider that parts of ArcGIS contain code going back to the 1980's (if not earlier). Back then there were severe limitations on directory and file names: the software assumed names were short (usually 13 characters or less), contained no special characters other than spaces, and did not begin with a numeric digit. (Even this description isn't exactly right, but it's close.) People still run into mysterious problems traceable to this old code. –  whuber May 3 '12 at 20:28
    
@whuber is bang on. It's not just spaces though, hyphens, -, also cause trouble because sometimes they're okay and sometimes they're not. See an arcgisscripting method for sanitizing a filename? –  matt wilkie May 9 '12 at 19:02
add comment

3 Answers

up vote 10 down vote accepted

One reason is because spaces carry special meaning in several programming/scripting languages.

Making a habit of naming files and folders with underscores is a good practice because then the " " (spaces) will not be treated as a new-line by some languages.

Example - A folder called "GIS Data" is a bad folder name. This is because if I try to access it with a script or some programming language I have to treat the spaces with special care.

If I don't tell it that the spaces are indeed spaces and not new-lines, then it will try to access "GIS" and "Data" as separate folders, but they are not.

In Unix bash from the command line I can use ls command to list the files and folders in a given directory.

ls GIS Data

Result:

ls: GIS: No such file or directory
ls: Data: No such file or directory

Error!

I now have to either use backslashes '\' or quotes '' to prevent the spaces being treated as newlines!

ls '1 2 3' or ls 1\ 2\ 3

The above two commands now treat the spaces as spaces.

Several ArcGIS geoprocessing tools do not like spaces in file or folder names in ANY part of the path to the data source. They will usually just fail with some kind of generic Error 99999.

share|improve this answer
add comment

There are some geoprocessing tools that will fail if there are spaces in file names. Thus, it's best to avoid them all together.

share|improve this answer
3  
Within Esri software, coverages and raster files never tolerated spaces in the names. Placing data sets on a Windows desktop was/is problematic because the folder is actually based in "Documents and Settings" (thus introducing spaces into the whole path name). Shapefiles are much more forgiving and spaces are possible, and I believe feature classes can now have a space and not crash, but old habits die hard. I agree with Jeff Berry - best to avoid them. –  dianamaps May 3 '12 at 17:38
add comment

Simply put - it's because spaces in command lines are treated at delimiters. So:

delete C:\directory\file number 1.shp

won't work on most operating system command lines without adding quotes:

delete "C:\directory\file number 1.shp"

Many GIS tools are command-line based so its just simpler to use under-scores if you're in an environment where the command-line is common. If you're solely a windows user you can probably get away with just leaving spaces in.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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