1
$\begingroup$

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?

$\endgroup$
2
  • 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
    Commented Jun 13, 2016 at 18:05
  • $\begingroup$ This packages together are software. So i need only import a package containing all other $\endgroup$
    – ivan
    Commented Jun 13, 2016 at 18:30

1 Answer 1

1
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ It might be useful to do something like FileNameJoin[{NotebookDirectory[], #}] & /@ FileNames["*.m"] to get a list of full file paths. $\endgroup$ Commented Jun 14, 2016 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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