Re: Path to *.m file
- To: mathgroup at smc.vnet.net
- Subject: [mg86447] Re: Path to *.m file
- From: David Bailey <dave at Remove_Thisdbailey.co.uk>
- Date: Tue, 11 Mar 2008 03:01:37 -0500 (EST)
- References: <fr0cr7$ekp$1@smc.vnet.net> <fr2mei$o2t$1@smc.vnet.net>
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 http://www.dbaileyconsultancy.co.uk