9
$\begingroup$

I've searched the documentation, this forum and with google, but I was not able to find how to ask Mathematica to give back the name of the current notebook file one is working on. Perhaps something with EvaluationNotebook[], but that gives a NotebookObject. How is it possible to use this information to retain just the filename?

$\endgroup$
3
  • 4
    $\begingroup$ AbsoluteOptions[EvaluationNotebook[], WindowTitle] ? $\endgroup$
    – Kuba
    Sep 16, 2013 at 11:49
  • 6
    $\begingroup$ or if it is saved (is it?): NotebookFileName[EvaluationNotebook[]] $\endgroup$ Sep 16, 2013 at 11:49
  • $\begingroup$ The notebook is indeed saved, that was precisely what I was searching for... Thanks, once again! $\endgroup$
    – Gabriel
    Sep 16, 2013 at 14:21

1 Answer 1

16
$\begingroup$

If the notebook is saved, you can use:

NotebookFileName[EvaluationNotebook[]]

or simply (thanks to @rm -rf)

NotebookFileName[]

and if it's just the file's name you are after:

NotebookFileName[] // FileNameSplit // Last

Alternatively, even for unsaved notebooks, try:

CurrentValue[EvaluationNotebook[], {"NotebookFileName"}]
$\endgroup$
0

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.