Setting working directory in mathematica

One of mathematica annoyances when working with external files (various import/export functions), is that it defaults to the user's Documents directory. I usually keep the data/graphics files  in the same directory as the mmka notebook and its painful to specify the full path every time.

Here is a command that sets the working directory to the notebook directory.

SetDirectory[
DirectoryName[
ToFileName["FileName" /. NotebookInformation[SelectedNotebook[]]]]]

UPDATE: Easier (thanks Pedro!):
SetDirectory@NotebookDirectory[]

 

One thought on “Setting working directory in mathematica

Comments are closed.