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?
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.
There are some geoprocessing tools that will fail if there are spaces in file names. Thus, it's best to avoid them all together.
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.
-
, also cause trouble because sometimes they're okay and sometimes they're not. See an arcgisscripting method for sanitizing a filename?