If I open c:\test1\test1.nb and click

Mathematica MenuBar - File - Save as...

then a window for Save as... pops up, and the default save path is

This is a story everyone knows and there is nothing surprising about it.

My question is, can I change the default save path of test1.nb, to
by executing some code on test1.nb?

In other words, when c:\test1\test1.nb is open(=working on it), and by typing some codes and pressing Enter key on test1.nb, can we change the default save path of test1.nb to c:\test2\test2.nb ?

Also, everything that happened and edited on test1.nb so far should be ignored(=vanished).

This question is related to the solution (still unresolved) of

Hyperlinks that open smoothly in the same window

Some progress has been made :

Save as custom folder succeeded! But in two steps


2 Answers 2

CopyFile["C:\\obr\\test1.nb", "C:\\test2\\test2.nb"]
  • $\begingroup$ Thank you but, I think you misunderstood my question. After typing and executing your code on test1.nb, then if I click Save as... in the menu bar, then we see highlighted default path is still "C:\\test1\\test1.nb". So not changed... It should be changed to "C:\\test2\\test2.nb" to be accepted as an answer. $\endgroup$
    – imida k
    Feb 4 at 11:05
  • $\begingroup$ So then use NotebookOpen["C:\\test2\\test2.nb"]; NotebookClose[]. $\endgroup$ Feb 4 at 11:33
  • $\begingroup$ It may seem like I'm forcing myself to find fault, again, the code in the comment isn't appropriate answer to me. Because... the notebook(.nb) itself was changed. The proper solution may be... a kind of editing some part of front-end or notebook related property. $\endgroup$
    – imida k
    Feb 4 at 12:11
  • 1
    $\begingroup$ @imida k: I do not get your point. Once you use Save As... with your new default path wouldn't you be in the same situation as with my code? $\endgroup$ Feb 4 at 15:15
  • $\begingroup$ If the question is approached in a common, practical sense, it will be ruined. It should be approached very delicately. Because this question is related with another question - smooth transition of mathematica window. mathematica.stackexchange.com/questions/297151/… There must not be NotebookClose[] or NotebookOpen[], because such command interrupt smooth transition. $\endgroup$
    – imida k
    Feb 4 at 22:36

Change NotebookBrowseDirectory with SetOptions.

SetOptions[$FrontEndSession, NotebookBrowseDirectory -> "C:\\"]
FrontEndExecute[FrontEndToken[InputNotebook[], "SaveRename"]]
  • $\begingroup$ Thank you, can you go further, including even ** file name **? $\endgroup$
    – imida k
    Feb 5 at 13:30
  • 2
    $\begingroup$ It does not work with already saved notebook, only with notebook that has not been already saved. $\endgroup$ Feb 5 at 13:41
  • $\begingroup$ @ azerbajdzan : I was thinking the same thing, but didn't write it down for fear it would be mixed with the content of the first comment. $\endgroup$
    – imida k
    Feb 5 at 13:45
  • $\begingroup$ If I recall correctly, this option is only applicable on Windows and Linux. Mac will ignore it. $\endgroup$
    – ihojnicki
    Feb 5 at 15:27
  • $\begingroup$ @ihojnicki mathematica.stackexchange.com/questions/297619/… $\endgroup$
    – imida k
    Feb 6 at 19:08

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.