MathGroup Archive 2008

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

Search the Archive

Re: Path to *.m file

  • To: mathgroup at
  • Subject: [mg86447] Re: Path to *.m file
  • From: David Bailey <dave at>
  • Date: Tue, 11 Mar 2008 03:01:37 -0500 (EST)
  • References: <fr0cr7$ekp$> <fr2mei$o2t$>

Albert Retey wrote:
> 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
I too would like a way to determine the path of a .m file while it is 
being loaded by Get. None of the replies provide a fool-proof way of 
doing this (e.g. in the not unusual case that you have two files with 
the same name in different directories). It would be nice if Wolfram 
Research added this to their 'to do' list!

David Bailey

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