@stacker, I was hoping for something cleaner. Both Adhi and iKIsR's answers would return the whole filepath including filename. I'd have to split the string using '/' for Linux/Mac and '\\', then strip it off the end. Is there not a single command to get the directory?
–
GarrettFeb 7 '14 at 11:55

1

Python as well as Blender provide path util functions, you shouldn't ever split using / and \`. Or at least use os.path.sep` to get the separator for the current platform. But keep in mind Blender's own notation for relative paths (starting with //). And always check windows compatibility, python may fail for paths which are directly on a drive (drive missing the colon or the backslash).
–
CoDEmanXFeb 7 '14 at 14:01

you missed to escape the backslash, edited your answer to show two ways to handle them. General note: with raw strings, you can't have a \ as last character, nor can you escape it like \\ (will be used literally, as double backslash, repr(r"\\") gives \\\\ ). [had to add a space after \ for stackexchange]
–
CoDEmanXFeb 7 '14 at 16:51