How to set an absolute path name using SetDirectory?

I tried the following:

Directory[]

/Users/John

SetDirectory["Library/Mathematica"]

/Users/John/Library/Mathematica


The documentation for SetDirectory says:

For a relative path name, SetDirectory sets the directory relative to the current working directory.

So it seems that SetDirectory interprets my argument as a relative path name. How can I get SetDirectory to interpret my argument as an absolute path name, so that the result is /Library/Mathematica instead of /Users/John/Library/Mathematica?

Not really a Mathematica specific question but in Mac OS X absolute paths begin with a / character exactly as you give in your desired result, so

SetDirectory["/Library/Mathematica"]


If you want Mathematica to interpret it as an absolute path, why don't you pass it one? In Windows:

SetDirectory["D:\\Library\\Mathematica"]

will set the path to D:\Library\Mathematica.

• are the double backslashes really necessary, in Windows? – magma Jul 14 '14 at 9:22
• @magma - Apparently not, but I saw them in a notebook I got from WRI, and I sticked to it. – stevenvh Jul 14 '14 at 9:25
• @magma - Yes, otherwise you'd get the "Unknown string escape" error. When you copy paste a file path within a Mathematica string (""), MMA will prompt you to allow it to insert escape--whatever that means--and you should pick "Yes". – seismatica Jul 14 '14 at 9:57
• @seism - I tried it with a single backslash, and it also works. No error, no warning, no prompt. – stevenvh Jul 14 '14 at 10:00
• @stevenvh I have no idea why mine showed the error. I took a screenshot of it: !Mathematica graphics. Could you help me use single backlash without error? – seismatica Jul 14 '14 at 10:20