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


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

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

From Jesse Perla <jesseperla@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: What does NotebookDirectory[] do for .m files?
Date 2012-04-18 07:55 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jmls2a$jel$1@smc.vnet.net> (permalink)
References <jm8qeg$ja9$1@smc.vnet.net> <jmdsop$ac3$1@smc.vnet.net> <jmgr4e$pgr$1@smc.vnet.net>

Show all headers | View raw


On Monday, April 16, 2012 6:09:18 AM UTC-4, Alexey Popkov wrote:
> "David Bailey"
> > On 13/04/2012 10:08, Jesse Perla wrote:
> > 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.

Thanks, I understand my confusion now.

> > 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!

> Print["$Input is ",$Input];
> Print["$InputFileName is ",$InputFileName];
What if I am running command-line mathematica?  I tried "math.exe < myfile.m" with all three of those variables, to no avail.


To take a more direct approach, what I really want is the ability save output relative to where I run my Mathematica file from (in both the Windows FrontEnd for debugging and command-line linux when I run on a cluster).

It looks like:
* "Directory[]" is set to the current system path when run from the command line.  So if I was careful to run the command-line from the directory of the current .m file, it should work
* "Directory[]" is set to some system default when I open a .m file in the front-end and run it.

So here is a proposed solution, which works on my Windows machine at least:

notebookDirectoryExists = Check[NotebookDirectory[],0]
outputDirectory = If[notebookDirectoryExists == 0, Directory[], notebookDirectoryExists]
Print["outputDirectory is ",outputDirectory]; 

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous 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