MathGroup Archive 1998

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

Search the Archive

Re: Re: Finding the Path to the Active Notebook




Paul Abbott wrote:

> Adalbert Hanszen wrote:
>
> > Does anybody know a way, how to programmatically find out, from which
> > directory the active notebook was loaded?
> >
> > I am looking for something like MyOwnPath[] returning me the full path
> > to the active notebook (or None, if the notebook has just been typed in
> > without any Notebook-loading).
>
> Do you really need this. Doesn't SelectedNotebook[] provide the
> functionality you need for working with a particular Notebook?

If you want to work with a particular notebook, it is not necessary, but
if you need to load any other file located in the same directory as the
current notebook (e.g. a template for an output to another file), you
need the path (because the current working directory can be set to any
other directory as well).


There is an undocumented Mathematica function which gives the
Information needed: NotebookInformation

If you want the Filename of the Notebook as a string, you can define the
following function:
NBFileName[nb_NotebookObject]:=ToFileName@("FileName"/.NotebookInformation[nb]/.{"FileName"->""});

Now NBFileName[SelectedNotebook[]] returns the filename of the selected
Notebook.


If you just want the Path of the notebook, the following will do that:
NBPath[nb_NotebookObject]:=ToFileName@("FileName"/.NotebookInformation[nb]/.{"FileName"->""})[[1]];

NBPath[SelectedNotebook[]]

If the Notebook has not yet been saved, the returned string is empty.


Another problem, which I have not been able to solve yet is how to get
the path where a PACKAGE is located. ContextToFileName does not give
the whole path. So I cannot open a file that is located in that
directory by using OpenRead.
Does anyone know a solution?

Reinhold
____________________________________________________________________
Reinhold Kainhofer  | e-mail: reinhold.kainhofer@kfunigraz.ac.at
Strassoldog. 4/3/17 | http://www.cryogen.com/rk 8010 Graz, Austria  |
http://www.geocities.com/Athens/9145




  • Prev by Date: Re: Forcing output in FindMinimum
  • Next by Date: Re: About plotting a surface
  • Prev by thread: Re: Finding the Path to the Active Notebook
  • Next by thread: Re: Re: Finding the Path to the Active Notebook