0
$\begingroup$

I want a global setting for Mathematica that changes the default directory to the current folder where the Mathematica's file therein. When I want to change the directory to the current folder, I use SetDirectory[NotebookDirectory[]] command at the top of my code to change the directory. Is there any global setting in Mathematica that changes the directory to a current folder where the Mathematica file exists there?

$\endgroup$
  • 2
    $\begingroup$ The problem is that you can open the notebook without starting the kernel. And current directory is a kernel's setting. You / the FrontEnd can also start the kernel without any particular notebook or with a non saved notebook. So there are many 'buts' with SetDirectory when Mathematica starts. Shortly, you can edit init.m file but NotebookDirectory[] may not be available and you will often get annoying messges. $\endgroup$ – Kuba Aug 16 at 7:00
  • $\begingroup$ Dear @Kuba, If want to apply SetDirectory[NotebookDirectory[]] command when the kernel starts, what shall I do? $\endgroup$ – AYBRXQD Aug 16 at 7:02
  • $\begingroup$ You can append it to your Kernel/init.m file, see mathematica.stackexchange.com/a/63741/5478 $\endgroup$ – Kuba Aug 16 at 7:26
  • 2
    $\begingroup$ The problem is that there is no NotebookDirectory[] when the kernel starts. As an example create a new notebook without saving it and issue the SetDirectory command and you will see what I mean. $\endgroup$ – Bill Watts Aug 16 at 7:31

Your Answer

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

Browse other questions tagged or ask your own question.