Re: How does a notebook get its own filename or directory?
- To: mathgroup at smc.vnet.net
- Subject: [mg50115] Re: How does a notebook get its own filename or directory?
- From: Joseph Gwinn <JoeGwinn at comcast.net>
- Date: Sun, 15 Aug 2004 03:15:08 -0400 (EDT)
- References: <cfkal5$fac$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <cfkal5$fac$1 at smc.vnet.net>, Bill Rowe <readnewsciv at earthlink.net> wrote: > On 8/13/04 at 5:56 AM, JoeGwinn at comcast.net (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. > >Currently, I just manually put the full pathname in the notebook's > >code, which works but is a problem if I move the directory. > > >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. > >However, all the directory-related and path-related commands in > >Mathematica 5.0 seem to be concerned only with the location of the > >Mathematica kernel and its libraries, and not at all concerned with > >the location of the notebook. Now, the kernel has to know where > >the notebook lives, so the problem is to persuade the kernel to > >speak. > > I've put the following in my init.m file to address this issue > > NotebookDirectory[]:= > DirectoryName@ToFileName["FileName"/.NotebookInformation@EvaluationNoteboo > k[]] > > Once the notebook has been saved, NotebookDirectory[] returns the path to > where it is currently. That's a nice trick. Thanks, Joe Gwinn