From: M.Roellig on
Hi group,

i would like to create an application package that included a data
directory that can should be accessable for commands in the
application. Of course I can hard-code the path in my .m file but what
is the proposed way to do this in case I would like to provide the
package to other users which might install the package in a completely
different directory?

At first I thought that the Workbench should offer some capability of
replacing Workbench$Path variables when the package is deployed to a
folder, but this is not the case.

I then thought about appending the data directory to the path using
something like
AppendTo[$Path, NotebookDirectory[]<>"/Data"]
in the .m file which fails because a package file is not a notebook or
has never been saved as on.

Is there any way to derive the installation directory of an
application from within the application?


Cheers,

Markus

From: Albert Retey on
Hi,

> i would like to create an application package that included a data
> directory that can should be accessable for commands in the
> application. Of course I can hard-code the path in my .m file but what
> is the proposed way to do this in case I would like to provide the
> package to other users which might install the package in a completely
> different directory?

Actually I don't know if or what the recommended way to handle this is,
but what I have done and what seems to work but is a little complicated
is this:

1) find where your package is installed (Assuming your package is called
MyPackage and will be loaded with e.g. Needs["MyPackage`"]):

installdir=First[FindFiles["MyPackage",$Path]]

2) now construct the path to your data directory from that path and save
it to a global variable:

$MyPackageDataDirectory=FileNameJoin[{installdir,"Data"}]

there are some pitfalls like which package will be used if you happen to
have more than one installed etc., which you might want to handle or not...

hth,

albert

From: Hannes Kessler on
On 19 Jun., 13:47, "M.Roellig" <markus.roel...(a)googlemail.com> wrote:
> Hi group,
>
> i would like to create an application package that included a data
> directory that can should be accessable for commands in the
> application. Of course I can hard-code the path in my .m file but what
> is the proposed way to do this in case I would like to provide the
> package to other users which might install the package in a completely
> different directory?
>
> At first I thought that the Workbench should offer some capability of
> replacing Workbench$Path variables when the package is deployed to a
> folder, but this is not the case.
>
> I then thought about appending the data directory to the path using
> something like
> AppendTo[$Path, NotebookDirectory[]<>"/Data"]
> in the .m file which fails because a package file is not a notebook or
> has never been saved as on.
>
> Is there any way to derive the installation directory of an
> application from within the application?
>
> Cheers,
>
> Markus

System`Private`$InputFileName is another possibility although it may
change in the future:
http://groups.google.de/group/comp.soft-sys.math.mathematica/browse_thread/thread/6eeff3e9ed2b51cf/f9507690fde98eec?pli=1

Best regards,
Hannes Ke=DFler