2
$\begingroup$

This question is different from the answer here Infix form of PutAppend ( >>> ) does not work with variable becasue it is dealing with folders and not filenames.

I have a file path which I save to a varible using the FileNameSetter. I then use the StringJoin to add the last folder name to this path. When I do this with a notebook file and then use NotebookEvaluate for example, Mathematica understands that this variable is a file location and executes without a problem. However when I do the same thing for a package and use the Get (or <<) Mathematica doesn't seem to understand that the variable is a location.

Setting up the file location

FileNameSetter[Dynamic[DashboardFile]];
DashboardFile
SetDirectory[DirectoryName[DashboardFile]]
PackageLocation = DirectoryName[DashboardFile] <> "Packages"


"\\\\ecsdbn-srv-02\\lara_jordan$\\Cleaner Kumba\\my redev\\tabview \
v1.6.nb" 
"\\\\ecsdbn-srv-02\\lara_jordan$\\Cleaner Kumba\\my redev"
"\\\\ecsdbn-srv-02\\lara_jordan$\\Cleaner Kumba\\my redev\\Packages"

Setting up the package location

PackageA = PackageLocation <> "\\HA1Package.m"
<< PackageA
<< "\\\\ecsdbn-srv-02\\lara_jordan$\\Cleaner Kumba\\my redev\\Packages\\HA1Package.m"

"\\\\ecsdbn-srv-02\\lara_jordan$\\Cleaner Kumba\\my redev\\Packages\\HA1Package.m"
Get::noopen: Cannot open PackageA. >>
$Failed

In the third line in the code above I have simply copied and pasted the value of PackageA just to the right on the << so I know that the location stored in the variable PackageA is valid.

I need this to work becasue I have hundreds of packages where each new user will just be asked to enter one file location that will automatically be used for all packages.

$\endgroup$
6
  • $\begingroup$ I have marked this question as a duplicate because the cause is already explained for Put. Your question will not be deleted, and will serve as a signpost for others to find the original question. +1 (In brief: use Get[PackageA]) $\endgroup$
    – Mr.Wizard
    Sep 4, 2013 at 10:55
  • $\begingroup$ Thanks, that works. Can you explain though why it works? The other answer which you directed me to I don't understand at all. $\endgroup$
    – lara
    Sep 4, 2013 at 11:02
  • 1
    $\begingroup$ Since that other answer is my own I'm afraid I may not be able to explain it better. Put simply, Mathematica treats << (and >> and >>>) in a highly unusual way: anything to the right of these operators is recognized as a String, even without the " " marks. Therefore your code is trying to read in a file with a literal name of PackageA. $\endgroup$
    – Mr.Wizard
    Sep 4, 2013 at 11:07
  • $\begingroup$ Oh ok thanks, that is the short and sweet answer which I do understand. Thanks so much. $\endgroup$
    – lara
    Sep 4, 2013 at 11:07
  • $\begingroup$ You're welcome. $\endgroup$
    – Mr.Wizard
    Sep 4, 2013 at 11:09

0

Browse other questions tagged or ask your own question.