5
$\begingroup$

I am aware of this question: Relative paths for portable notebooks in Mathematica

In the answer it is said that

Directory[NotebookDirectory[]]

is the equivalent to

cd ..

Which does not work for me. Directory[] does not take an argument. So what is the correct solution to go to your parent directory?

$\endgroup$
  • $\begingroup$ You missed the part of an answer, it should be: SetDirectory[NotebookDirectory[]]. $\endgroup$ – m0nhawk Sep 20 '15 at 9:26
  • $\begingroup$ But this does change to the directory where my notebook lies. But I want to go to the one above. $\endgroup$ – mcocdawc Sep 20 '15 at 9:31
15
$\begingroup$

If you want to have the parent directory of the current directory, use

ParentDirectory[].

The parent directory of your notebook can be found using:

ParentDirectory[NotebookDirectory[]]

If you want to set the parent of the notebook directory as the current directory use:

SetDirectory[ParentDirectory[NotebookDirectory[]]]

Note that if you use NotebookDirectory[] your notebook has to be saved first (i.e., it doesn't work on an untitled notebook that you just created using File > New)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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