Bug introduced in 12.1.0 and fixed in 12.2.0 (or 12.1.1?)

Could anybody help?

NotebookDirectory[] function began working wrong in 12.1 (the bug was not present in 12.0 and earlier versions).

When folder name includes Russian (Cyrillic) symbols, the function returns wrong path. Namely, the path contains all the folders up to the one including Сyrillics.

Example: if file path is "C:\folder1\folder2\папка\test.nb" NotebookDirectory[] returns "C:\folder1\folder2".

Any idea?

  • 1
    $\begingroup$ Next time, please do not use the bugs tag when initially asking a question, until a different user is able to confirm that what you have observed is a bug. This time, I'll let it slide since ilian was able to provide confirmation. $\endgroup$ Commented Apr 17, 2020 at 4:08
  • $\begingroup$ Thanks for trying my idea, clearly it is not quite right so I'll delete the attempted answer for now. Could you tell me what is $CharacterEncoding on your system? $\endgroup$
    – ilian
    Commented Apr 17, 2020 at 6:14
  • $\begingroup$ it returns the following: WindowsCyrillic $\endgroup$
    – Alexander
    Commented Apr 17, 2020 at 6:24
  • $\begingroup$ I do not reproduce the bug with version 12.2.0 on Windows. $\endgroup$ Commented Mar 6, 2021 at 19:53

1 Answer 1


This is a certainly a bug. The fix for it is going to be available in the next release (version 12.1.1).

In the meantime, perhaps the following workaround code may help


Internal`EncodeCharacters[str_, enc_] := 
       Quiet[FromCharacterCode[ToCharacterCode[str], enc]]

(assuming it does, it could be placed in the kernel init.m file for convenience)

enter image description here

  • $\begingroup$ Dear Ilian, thank you for the answer! I place nb file directly at C: disk. On evaluating the suggested command and Notebookdirectory[] an error message appeared: "String expected at position 1 in DirectoryName[ByteArrayToString[StringToByteArray[D:\test.nb,Unicode],Unicode)]]. Could you please help with correcting the "patch"? $\endgroup$
    – Alexander
    Commented Apr 16, 2020 at 21:44
  • $\begingroup$ Apologies, I am not on Windows at the moment. Please see if the updated variant seems to work. $\endgroup$
    – ilian
    Commented Apr 16, 2020 at 22:02
  • $\begingroup$ Dear Ilian, thank you for these $\endgroup$
    – Alexander
    Commented Apr 17, 2020 at 5:35
  • $\begingroup$ tryes to fix the bug. This is the next result: String expected at position 1 in DirectoryName[ ByteArrayToString[StringToByteArray[C : \test.nb, Unicode], Unicode]] That is, the same error message still appears $\endgroup$
    – Alexander
    Commented Apr 17, 2020 at 5:36
  • 1
    $\begingroup$ Dear Ilian, I confirm that this patch works at my computer too. Thank you very much!!! $\endgroup$
    – Alexander
    Commented Apr 19, 2020 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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