MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Command to get a notebook's directory?

  • To: mathgroup at
  • Subject: [mg22942] Re: [mg22927] Command to get a notebook's directory?
  • From: John Fultz <jfultz at>
  • Date: Fri, 7 Apr 2000 02:54:27 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

> Hi all,
> This seems like a pretty simple question, but I am having the hardest time
> finding the answer.  Let's say I save a notebook in a directory called
> "c:\myfiles\mynotebooks".  Is there a command I can use from within this
> notebook to determine this directory?
> The purpose is to have an Export command that is able to export data to the
> same directory in which the notebook is saved.  If I move the notebook, I
> don't want to have to manually change the Export command.
> The Directory[] command gives the working directory, which is not
> necessarily the same as the notebook's directory.
> Thanks,
> Jordan

This information is provided by the function NotebookInformation[], which
is documented but not very thoroughly.  For example...

n[35]:= NotebookInformation[EvaluationNotebook[]]

Out[35]= {"FileName" -> 
      FrontEnd`FileName[{$RootDirectory, "G:", "TEMP"}, "AngleGrid.nb", 
        CharacterEncoding -> "WindowsANSI"], 
    "FileModificationTime" -> 3.115662974`*^9, 
    "WindowTitle" -> "AngleGrid.nb", 
    "MemoryModificationTime" -> 3.163999969578125`*^9}

Note the "FileName" option here, which can be picked out and surgically
altered to get the path information.  The code below is one way you
could do it...

  FrontEnd`FileName @@ 
    HeldPart["FileName" /. NotebookInformation[EvaluationNotebook[]], 1]]

For obvious reasons, this will not work on a notebook which has not
been saved yet (i.e. an untitled notebook).


John Fultz
jfultz at
User Interface Group
Wolfram Research, Inc.

  • Prev by Date: Re: Apparently easy ODE
  • Next by Date: Re: best solution?
  • Previous by thread: Re: Command to get a notebook's directory?
  • Next by thread: Re: Command to get a notebook's directory?