Re: What does NotebookDirectory do for .m files?
- To: mathgroup at smc.vnet.net
- Subject: [mg126088] Re: What does NotebookDirectory do for .m files?
- From: "Alexey Popkov" <lehin.p at gmail.com>
- Date: Mon, 16 Apr 2012 06:08:22 -0400 (EDT)
- Delivered-to: firstname.lastname@example.org
- References: <email@example.com> <firstname.lastname@example.org>
"David Bailey" <dave at removedbailey.co.uk>: news:jmdsop$ac3$1 at smc.vnet.net... > 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! It seems that in version 8.0.4 $InputFileName gives complete path to the .m-file. Evaluating << ExampleData/input.m gives $Input is ExampleData/input.m $InputFileName is C:\Program Files\Wolfram Research\Mathematica\8.0\Documentation\English\System\ExampleData\input.m while evaluating FilePrint["ExampleData/input.m"] gives Print["$Input is ",$Input]; Print["$InputFileName is ",$InputFileName];