[Date Index] [Thread Index] [Author Index]
Re: Re: Command to get a notebook's directory?
Yes, an approach using NotebookDirectory is incorrect and would cause bugs with certain usage patterns. NotebookDirectory gets a global option in the front end. This global option is set every time you use the File->Open... command to open a notebook and happens to be set to the directory to which you last opened (or saved using Save As...) a notebook file. This, however, is not necessarily the same thing as the directory in which a particular notebook exists. Example... You open up c:\dir1\notebook1.nb using File->Open... NotebookDirectory will be set to c:\dir1 You open up c:\dir2\notebook2.nb using File->Open... NotebookDirectory will be set to c:\dir2 Now, you want to know the notebook that notebook1.nb (still open) resides in. You can only get that information via NotebookInformation. Note that you can also open up a notebook in such a way as to not even set the NotebookDirectory option. For example, if you open a notebook in the File->Notebooks menu (which records recently opened notebooks), the NotebookDirectory option will not be set. Now, on the other hand, you have to keep in mind that NotebookInformation will not always return a "FileName" option. It will only do so if the notebook has been given a name (i.e. saved to disk). If you evaluate NotebookInformation in a new notebook, no "FileName" option will be returned. Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc. > Adalbert/John, > > Thanks to both of you for your reply. Between the time I wrote my message > and the time you replied I also (after quite a bit of time!) came up with > the following > > ToFileName[ NotebookDirectory /. Options[$FrontEnd, > NotebookDirectory][] ] > > Since you both used the NotebookInformation function, I am wondering if > there is any reason my approach may be buggy. Is there any hidden problems > in doing it my way? > > Thanks, > > Jordan > > "Adalbert Hanssen" <hanssen at zeiss.de> wrote in message > news:8ck0rd$g59 at smc.vnet.net... > > Hi, > > > > according to [mg20941], the solution is > > > > ToFileName[First["FileName" /. > > NotebookInformation[EvaluationNotebook] > > ] /. $RootDirectory->"" > > ] > > > > greetings > > > > Adalbert > > > > >