Re: Path to *.m file
- To: mathgroup at smc.vnet.net
- Subject: [mg86529] Re: Path to *.m file
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Thu, 13 Mar 2008 04:31:44 -0500 (EST)
- References: <fr0cr7$ekp$1@smc.vnet.net> <fr2mei$o2t$1@smc.vnet.net> <fr5e8e$odd$1@smc.vnet.net> <fr7onk$37d$1@smc.vnet.net>
Albert Retey wrote:
> Hi,
>
>> 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).
>
> I absolutely agree with your wish that this information should be
> available without any hacking but I think that there is no way to load a
> file with Get which is not the first in FileNames[filename,$Path]
> unless you use an absolute path for filename. The latter is easy to
> handle and covered with the else condition in:
>
> Catch[If[
> FileType[$Input]=!=File,
> First[FileNames[$Input,$Path]/.{}:>Throw[$Failed]],
> $Input
> ]]
>
> so I think the above construct should work for the case you named.
>
>> It would be nice if Wolfram
>> Research added this to their 'to do' list!
>
> I'm sure you have seen the post of Carl Woll about an undocumented
> private variable that holds that information. Looks like the people at
> Wolfram found this information valuable, too, so it probably is only a
> small effort to provide that information to the users/package developers
> without hacks and workarounds.
>
> Sorry for the post with only marginal new information but maybe keeping
> the thread alive convinces someone that we really want that little
> information accessible :-)
>
> albert
>
Albert,
I take your point, although technically there is still room for
uncertainty because the .m could create a file of the same name
somewhere earlier in the path. OK - I know that is a bit unlikely, but
since this information is easily obtainable from the OS, it would be
nice if Mathematica handed it on in a completely reliable way.
David Bailey
http://www.dbaileyconsultancy.co.uk