Consider our package awesomepackage.m.
If I put this file in FileNameJoin@{$UserBaseDirectory, "Applications"} I can easily import it in any notebook with a simple Needs["awesomepackage`"] (or similar command).
The same still works if I put awesomepackage.m in a subdirectory of Applications, like in FileNameJoin@{$UserBaseDirectory, "Applications","awesomepackage"}.
However, if for any reason I want my awesomepackage to be in some subsubdirectory of Applications, then I will have to use its full path, otherwise Mathematica will not be able to find it based on the context name alone.
Is there some convenient way to have Mathematica look for .m files by default in all (sub..)subdirectories of Applications, maybe up to some nested level?
The core idea is that I want to be able to change the exact location of awesomepackage.m without having to change the way it is imported in all the notebooks, and possibly without having to add some code in every notebook in which I want to import this package.
.mfiles. I would want the whole thing to be contained in a single directory so to be easily moved and "installed", and at the same time to be able to easily import it in a notebook without having to think of the full paths. What is the recommended method in this case? Should I put afoo.mfile where you put it in your example, and infoo.mwrite some code to tell MMA where to find the various "subpackages" necessary for the main one? – glS Aug 23 '16 at 12:51init.mdoes when inside a package directory structure. Can it be used for such purpuses? – glS Aug 23 '16 at 12:52Foo. Then you have a directory with the same name. Within you have multiple.mfiles,Sub1.m,Sub2.m, etc. Theinit.mfile containsGet["Foo`Sub1`"]; Get["Foo`Sub2`"]; .... You can load the whole package from a notebook using<<Foo`. If the sub-packages are somewhat independent and are meant to be loadable separately too, then that can be accomplished using<<Foo`Sub1`, i.e. the same commands used ininit.m. – Szabolcs Aug 23 '16 at 13:22Foo/Foo.mandinit.monly containsGet["Foo`Foo`"]. Then as your package is growins and you decide to add more sub-packages thatFoo.mwill depend on, you add them in the same directory as.mfiles and load them inFoo.musingBeginPackage["Foo`", {"Foo`Sub1`, ...}]. – Szabolcs Aug 23 '16 at 13:24