MathGroup Archive 2001

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

Search the Archive

RE: Notebook Filename

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30317] RE: [mg30312] Notebook Filename
  • From: Mikael Adlers <mikael at mathcore.com>
  • Date: Sat, 11 Aug 2001 03:39:41 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,
you can obtain some information about the current notebook by using

In[74]:=
NotebookInformation[InputNotebook[]] (* or you can use SelectedNotebook[] *)

Out[74]=
\!\({"FileName" \[Rule] 
      FrontEnd`FileName[{$RootDirectory, "E:"}, "397.nb", 
        CharacterEncoding \[Rule] "WindowsANSI"], 
    "FileModificationTime" \[Rule] 3.206177345`*^9, 
    "WindowTitle" \[Rule] "397.nb", 
    "MemoryModificationTime" \[Rule] 3.2062448790633764`*^9}\)


Now you only have to extract the FileName part. If the notebook has not been
saved the rule for "FileName" do not exist and therefore you have to add it
to the list of rules otherwise you will get the string "FileName" back
(the first matching rule is always used to you can always add an "emtpy"
rule last).
Then you drop the path of the filename and you end up with:


In[68]:=
GetNotebookFilename[nb_NotebookObject]:=Module[{fileN},
    fileN=
      ToFileName[
        "FileName" /. Join[NotebookInformation[nb],{"FileName"\[Rule] {}}]];
    StringDrop[fileN,StringLength[DirectoryName[fileN]]]
    ]

In[69]:=
GetNotebookFilename[InputNotebook[]]

Out[69]=
397.nb

If you want the path of the file you can use


In[72]:=
GetNotebookPath[nb_NotebookObject]:=Module[{fileN},
    fileN=
      ToFileName[
        "FileName" /. Join[NotebookInformation[nb],{"FileName"\[Rule] {}}]];
    DirectoryName[fileN]
    ]

In[73]:=
GetNotebookPath[InputNotebook[]]

Out[73]=
"E:\\"

Regards,
Mikael Adlers

------------------------------------------------------------------ 
 Mikael Adlers, Ph.D.          email: mikael at mathcore.com 
 MathCore AB                   phone: +4613 32 85 07 
 Wallenbergsgata 4             fax:         21 27 01
 SE-583 35 Linköping, Sweden   http://www.mathcore.com



> -----Original Message-----
> From: Doug Pickering [mailto:Pickering at BrandonU.ca] 
To: mathgroup at smc.vnet.net
> Sent: den 8 augusti 2001 07:34
> Subject: [mg30317] [mg30312] Notebook Filename
> 
> 
> Is there a way to identify the filename of the notebook in 
> use from within
> that notebook.
> 
> For example, if I open the notebook   "testintegral.nb"   can I use a
> function to give me the string "testintegral.nb"  ?
> 
> Thank you in advance,
> 
> Doug Pickering.
> 
> 
> 
> Doug Pickering
> Professor
> Dept of Mathematics and Computer Science
> Brandon University
> (204) 727-9674
> Pickering at BrandonU.ca
> 
> 


  • Prev by Date: Preparing Documents or Presentations in Mathematica?
  • Next by Date: Re: How can I acceralate calcution by improving coding?
  • Previous by thread: Re: Notebook Filename
  • Next by thread: Re: Notebook Filename