Message Boards Message Boards


Package that saves itself to given folder and name?

Posted 9 years ago
2 Replies
0 Total Likes


Is there a way for a mathematica package to save itself to given directory from command line???

That is if I Run the package it writes the package to given folder to given file name.


POSTED BY: Indrek Morell
2 Replies

Hmm... seems very complicated though. I have a metabolic model which is modified according to needs and it would be nice from the model to save a replica of itself every time calculations are performed. But it is not a critical problem thus I guess if it is complicated let it just be.

Thanks anyway!

POSTED BY: Indrek Morell

The issue is that, from the command line and with a .m file, the various functions (e.g., CurrentValue, NotebookDirectory,..., even making use of UsingFrontEnd) will not automatically give the location of the .m file since they are not being executed in the file itself but rather from the terminal, making use of the code in the .m file. So the code does not know internally where it came from.

But,... if you are evaluating the m file using Get from the command line, then you know where the file is--whether you specifically have gone to that directory or if the path to the directory is in the $Path variable. So, given that you know the directory where the package is located you can, externally set it to a parameter and have that parameter in the package with the appropriate CopyFile command to copy the file from the known directory to the desired directory. Of course you will now have a package in a new directory that, when you execute it from there, will attempt to copy itself to itself with a possibly unknown parameter. But you cold wrap that in Quiet to suppress any errors.

But the actual question is: why are you wanting to do this? And why from the command line?

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract