Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a structure of folders.

  1. Main Directory( has init.m, and name.m files)
  2. Subfolders under Main directory
    1. library ( has the packages, pacakge1.m, package2.m)
    2. Data (some xcel sheets and other data files) The init.m has the following commands Get[FileNameJoin[{NotebookDirectory[],"library", "Package1.m"}]]; Get[FileNameJoin[{NotebookDirectory[],"library", "Package2.m"}]];

Package1 has function1 and function2 definitions. Package2 has function3 and function4 definitions.

The Names.m file has the following the commands

Get[FileNameJoin[{NotebookDirectory[],"init.m"}]];
DeclarePackage["Package1`",{"function1", "function2"}];
DeclarePackage["Package2`",{"function3", "function4"}]

After evaluating the name.m file, I was expecting that calling function1 should execute the Package1`function1. However it is not happening. This is what I understand of Mathematica so far. I don't want to touch the init.m file in the Autoload folder of the userbase directory as I don't want to modify the contents. I just want my init.m in the local folder to run.

Workarounds anyone?

share|improve this question
    
In the second argument of BeginPackage you can specify additional contexts/packages that are needed. Is that what you want? –  Mr.Wizard Feb 17 '13 at 11:14
1  
Play around with the function FindFile until you get the relationship between context name and folder structure. Both \\package\\init.m, or \\package.m are found with "package`", as long as the base directory is in the path, no need to specify the full file name. Subcontexts are interpreted as subfolders. –  Rojo Feb 17 '13 at 16:26
    
Somewhat related. –  Leonid Shifrin Feb 17 '13 at 17:35
add comment

1 Answer

From the documentation:

NotebookDirectory[] gives the directory of the current evaluation notebook.

Your init.m is not the evaluation notebook and therefore this will not work. A simple test-case can be constructed when you create a test.m with a single line of code

Print[NotebookDirectory[]];

Then you open a new and unsaved notebook and Get this package. It will lead to an error

NotebookDirectory::nosv: The notebook NotebookObject[Untitled-1] is not saved. >>

Why don't you look at the directory structure of packages in the e.g. AddOns folder and follow the usual conventions?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.