# Possible bug in 12.3: NotebookDirectory[] returns not the notebook's own directory, but that of an also opened copy of that notebook

Bug introduced in 12.3

I am using Windows 10 and found a bug concerning NotebookDirectory (and also NotebookInformation) in 12.3. It can be easily reproduced. Create a new notebook and save it as notebook1 in a folder, lets say c:\folder1\notebook1. As expected, excecuting NotebookDirectory[] gives

c:\folder1


Now save the notebook and copy it (using the Explorer) into another folder named c:\folder2. Rename the copy to c:\folder2\notebook2.nb and open it in Mathematica, such that now both notebooks are open. (There is no need to excecute notebook2.nb, just open it) The bug is, that re-excecuting NotebookDirectory[] in notebook1.nb gives:

c:\folder2


instead of again c:\folder1 :-( This is of course not correct. I tested this on two machines, and saw the bug on both. Also I assigned different kernels to the notebooks. It does not matter.

Also, after closing and reopening Mathematica: If I open notebook1 alone I get the correct notebook directory, if I also open notebook2, I get for notebook1 the wrong directory.

With Mathematica 12.2 I had the problem not. However,I cannot exclude that the bug appeared with the latest Windows update.

Any ideas, what is going on?

• I reproduced this problem (12.3, Windows 10), with an additional problem - if I then close the second file (with or without executing anything), and try NotebookDirectory[] in the first file, I get an error: NotebookDirectory::nosv: The notebook NotebookObject[25501141-5cf3-49a4-916b-3b8b6fb97d14] is not saved. Jun 23, 2021 at 21:21
• NotebookInformation[] reveals that both notebooks have identical ExpressionUUIDs. Is this the source of the problem? Or is this expected? I do not know what this ID is used for.
– dnet
Jun 24, 2021 at 8:36
• Now I testet this with 12.2 on the same machine. No problem there. ExpressionUUIDs are identical there, too.
– dnet
Jun 24, 2021 at 8:42
• As my colleagues and me copy notebooks containing NotebookDirectory[] rather commonly, we will go back to 12.2 for now.
– dnet
Jun 24, 2021 at 8:51
• I reported the bug to Wolfram.
– dnet
Jun 24, 2021 at 9:01

I found an effective solution in this answer:

https://mathematica.stackexchange.com/a/257388/82311

CurrentValue[\$FrontEnd, FrontEndFrontEndObjectFormat] = "Legacy"


Thanks to josh and Kuba. In fact, we can find this "NotebookObject and CellObject now use a UUID string instead of specific FrontEndObject values" in incompatible changes of MMA. I think that's the problem.

• I got the same hint from Wolfram support. And some hint that the issue might be solved in 13.1. Let's hope.
– dnet
May 10 at 8:46

Sorry I can't make any comment because of my reputation.

Try with SetDirectory[NotebookDirector[]] as first line of you codeflow and then use Directory[] instead.

I had a similar problem and It worked for me.

• It doesn't work. You solution relies upun buggy NotebookDirectory[]`, and hence can't work reliably in principle. Dec 9, 2021 at 4:14