MathGroup Archive 2008

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

Search the Archive

Re: Path to *.m file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86386] Re: Path to *.m file
  • From: Albert Retey <awnl at arcor.net>
  • Date: Mon, 10 Mar 2008 02:02:52 -0500 (EST)
  • References: <fr0cr7$ekp$1@smc.vnet.net>

Hi,

> is there a way to  obtain the full path to a *.m file from within that 
> same file under Mathematica 6?

This gives the filename of the *.m file:

$Input

but if you put the file into one of the directories in $Path and load it 
with e.g.:

<< tst.m

or

<< tst`

you might get only a relative path, that is relative to one of the 
directories in $Path. This will give you the full path in that case:

First[FileNames["tst.m", $Path]]

I have not found a function which gives you the full path directly, but 
that does not mean it doesn't exist, probably someone else has found it :-)

this is how it could look like, it should handle the common cases, but 
it's not thoroughly tested for all OS and exotic cases:

myfullpath = Catch[If[
   FileType[$Input]=!=File,
   First[FileNames[$Input,$Path]/.{}:>Throw[$Failed]],
   $Input
]]


hth,

albert




  • Prev by Date: FindFit issue
  • Next by Date: Re: Re: NDSolve Question
  • Previous by thread: Re: Path to *.m file
  • Next by thread: Re: Path to *.m file