For example, I import several files with the following lines:

<< (NotebookDirectory[] <> "/psoPackage/psoGenericFunctions.m");
<< (NotebookDirectory[] <> "/psoPackage/calculateVelNiches.m");
<< (NotebookDirectory[] <> 
   "/objectiveFunctions/objective functions.m");
<< (NotebookDirectory[] <> "/psoPackage/bifurcationMainFunctions.m");
<< (NotebookDirectory[] <> "/objectiveFunctions/limiters.m");
<< (NotebookDirectory[] <> "/pseudoRandomGen/haltonSerie.m");
<< (NotebookDirectory[] <> "/Graphics/Graphics.m")

But I need to import the files in one line. For example: create a new file .m and include in this the package. So only import this new file. Anyone have any ideas how to do this?

  • 2
    $\begingroup$ Get[NotebookDirectory[] <> #] & /@ {firstFileName, secondFileName, ...}? However, why do you need to get them all in one line? I can't see much advantage in that myself, and it seems to detract from overall readability. $\endgroup$ – MarcoB Jun 13 '16 at 18:05
  • $\begingroup$ This packages together are software. So i need only import a package containing all other $\endgroup$ – ivan Jun 13 '16 at 18:30

Make a load.m file in the Notebook directory that has the lines:

<< "/psoPackage/psoGenericFunctions.m";
<< "/psoPackage/calculateVelNiches.m";
<< "/objectiveFunctions/objective functions.m";
<< "/psoPackage/bifurcationMainFunctions.m";
<< "/objectiveFunctions/limiters.m";
<< "/pseudoRandomGen/haltonSerie.m";
<< "/Graphics/Graphics.m"

In the notebook that is in the directory have the command:

<< (NotebookDirectory[] <> "load.m")

You may have to play around with the "/" marks depending upon your system.

| improve this answer | |
  • $\begingroup$ It might be useful to do something like FileNameJoin[{NotebookDirectory[], #}] & /@ FileNames["*.m"] to get a list of full file paths. $\endgroup$ – J. M.'s technical difficulties Jun 14 '16 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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