MathGroup Archive 2004

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

Search the Archive

Re: How does a notebook get its own filename or directory?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50072] Re: How does a notebook get its own filename or directory?
  • From: Marcus Stollsteimer <marcus314 at yahoo.com>
  • Date: Sat, 14 Aug 2004 01:50:21 -0400 (EDT)
  • References: <cfi8rj$4oa$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Joseph Gwinn wrote:

> I like to put multiple datafiles in a subdirectory of the same
> directory as the analysis notebook resides.
> It would be convenient if this Mathematica notebook could find
> these datafiles without help, but unfortunately I
> have not figured out how to do this.
(snip)
> What would solve the problem is if there were a way for a notebook
> to obtain the full pathname of the file containing that notebook.

Hi Joe,

I use the following function:

In[1]:=
SetDirToNotebookDir::usage=
    "SetDirToNotebookDir[] sets the working directory to the directory
of the evaluated notebook";

SetDirToNotebookDir[]:=
  Module[{MyNotebookDir},
    MyNotebookDir=
      DirectoryName@
        ToFileName@("FileName"/.NotebookInformation[
                  EvaluationNotebook[]]/.{"FileName"\[Rule]""});
    If[MyNotebookDir\[NotEqual]"",SetDirectory[MyNotebookDir];
      Print["Directory set to ",MyNotebookDir]]]


In[3]:=
Directory[]

Out[3]=
/home/marcus

In[4]:=
SetDirToNotebookDir[]

From In[4]:=
Directory set to \[InvisibleSpace]/home/marcus/mathematica/

In[5]:=
Directory[]

Out[5]=
/home/marcus/mathematica


see also
<http://forums.wolfram.com/mathgroup/archive/2004/Apr/msg00159.html>

HTH,
Marcus


-- 
Kant was right: The mind imposes order.
It also tells you how much to tip. -- W. Allen


  • Prev by Date: Re: To extract the power of variable
  • Next by Date: Re: Re: How to set linewidth in 3-D graphics?
  • Previous by thread: Re: How does a notebook get its own filename or directory?
  • Next by thread: Re: How does a notebook get its own filename or directory?