Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9654

Re: What does NotebookDirectory[] do for .m files?

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: What does NotebookDirectory[] do for .m files?
Date 2012-04-15 07:18 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jmdsop$ac3$1@smc.vnet.net> (permalink)
References <jm8qeg$ja9$1@smc.vnet.net>

Show all headers | View raw


On 13/04/2012 10:08, Jesse Perla wrote:
> NotebookDirectory[] correctly gives the location of the notebook for my .nb files, but I cannot seem to find an equivalent for my .m files?  Is there another approach?
>

There are two distinct cases here.

If you open a .m file in the FrontEnd, it is treated like a notebook, 
and NotebookDirectory will work on it.

If you use Get ( << ) to open the file, or it is opened because of a 
Needs command, then things get a bit trickier. While the .m file is 
being loaded in, $InputFileName is set to the name of the .m file, but 
not to the complete path! This is extremely inconvenient, because it is 
usually the path that you want! However, there is another undocumented 
variable that holds the complete path:

System`Private`$InputFileName

This has remained unchanged over several versions of Mathematica, and it 
is the only fully reliable way that I know of, to obtain this 
information. For example, my SuperWidgetPackage contains many other 
files within its directory, which I access by saving this variable as 
the package is first executed.

David Bailey
http://www.dbaileyconsultancy.co.uk

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What does NotebookDirectory[]  do for .m files? Jesse Perla <jesseperla@gmail.com> - 2012-04-13 09:08 +0000
  Re: What does NotebookDirectory[]  do for .m files? Vince Virgilio <blueschi@gmail.com> - 2012-04-14 07:16 +0000
  Re: What does NotebookDirectory[]  do for .m files? David Bailey <dave@removedbailey.co.uk> - 2012-04-15 07:18 +0000
    Re: What does NotebookDirectory[]  do for .m files? "Alexey Popkov" <lehin.p@gmail.com> - 2012-04-16 10:09 +0000
      Re: What does NotebookDirectory[]  do for .m files? Jesse Perla <jesseperla@gmail.com> - 2012-04-18 07:55 +0000

csiph-web