6
$\begingroup$

How can I use something like that

 NotebookEvaluate[
      "Mathematica\\SomeFile.nb"];

Instead of

 NotebookEvaluate[
      "B:\\Users\\icemt_000\\Documents\\Mathematica\\SomeFile.nb"];

where Directory[] is set to "B:\\Users\\icemt_000\\Documents"?

$\endgroup$
0

2 Answers 2

9
$\begingroup$

I think it should just work, but if not use

NotebookEvaluate[FileNameJoin[{Directory[], "Mathematica\\SomeFile.nb"}];

Also have a look at NotebookDirectory[]

$\endgroup$
6
  • $\begingroup$ Seems like you've made a typo (wrong position of comma) , this one should be correct NotebookEvaluate[FileNameJoin[{Directory[] , "Mathematica\\SomeFile.nb"}]; Thanks for help! $\endgroup$
    – icemtel
    Sep 4, 2015 at 9:10
  • $\begingroup$ @icemtel Indded. Typo fixed. $\endgroup$
    – Ajasja
    Sep 4, 2015 at 9:23
  • $\begingroup$ I notice that you have not posted in almost a year. Have you decided to no longer participate in this community? I hope not. :-( $\endgroup$
    – Mr.Wizard
    Aug 21, 2016 at 8:48
  • $\begingroup$ Hi @Mr.Wizard! Huh, is it that long already? I still read the occasional question:) But I've mostly switched to the Python ecosystem for my work-related stuff, so my lack of posts reflects my use of MMA. $\endgroup$
    – Ajasja
    Aug 21, 2016 at 9:09
  • 2
    $\begingroup$ @Mr.Wizard On the contrary, I believe the MMA.SE is one of the nicest communities on the stackexchange network (and I still wear my t-shirt with pride to various geek meetings:) However my work is mostly numerical, for which MMA is perhaps not the best. I’m using the Ipython notebook, numpy and pandas as well as mdtraj and am very satisfied with the setup. $\endgroup$
    – Ajasja
    Aug 22, 2016 at 8:37
5
$\begingroup$

Always better to use FileNameJoin than to type in the full path name as a string. Further, you should give the name of each directory in the path individually. So you should use

NotebookEvaluate[
  FileNameJoin[{Directory[], "Documents", "Mathematica", "SomeFile.nb"}]]

An alternative is not to specify the notebook file, but select it from a system open dialog. This can be done with

Module[{path},
  path = SystemDialogInput["FileOpen", "*.nb", WindowTitle -> "Select a notebook"];
  If[path === $Canceled, $Canceled, NotebookEvaluate[path]]]
$\endgroup$

Your Answer

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

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