This is causing me lots of problems. I found that issuing SetDirectory[NotebookDirectory[]];
in notebook A.nb
causes subsequent Directory[]
command in a separate notebook B.nb
and in different location to return the directory of A.nb
(even though SetDirectory[NotebookDirectory[]];
has also been issued earlier in B.nb
This is a problem, since I have scripts that uses relative folder paths. And if I happen to open a second notebook and change the Directory there to run something else, then come back to the first notebook, my script does not work now since the Directory has changed, unless I remember to issue SetDirectory[NotebookDirectory[]];
each time, and to remember to do this again when I change to a different notebook. So I keep issuing SetDirectory[NotebookDirectory[]];
all the time now. This is so confusing as I am not sure which directory I am in at any moment.
Steps to reproduce:
- open a notebook in some folder, type
SetDirectory[NotebookDirectory[]];
- open a notebook in different folder, type
SetDirectory[NotebookDirectory[]];
- Go back to notebook in step (1) and type
Directory[]
you will see it has changed to whatever the notebook in (2) was in.
Is this a bug? Is this the expected behaviour? How can one make SetDirectory[NotebookDirectory[]];
not change the Directory[]
of other open notebooks in different folders? Isn't the semantics of SetDirectory[NotebookDirectory[]]
meant to affect only the current notebook and not all open notebooks?
If SetDirectory[NotebookDirectory[]]
is meant to change the directory of all open notebooks, is there a solution to set the directory to the location of the current notebook, without having this global effect on all other notebooks?
I normally have few open notebooks, all in different places.
Version 10.1, windows 7