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

PackageLocation = DirectoryName[DashboardFile] <> "Packages"

"\\\\ecsdbn-srv-02\\lara_jordan$\\Cleaner Kumba\\my redev\\tabview \
"\\\\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. >>

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.

  • $\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
    Commented 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
    Commented 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
    Commented 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
    Commented Sep 4, 2013 at 11:07
  • $\begingroup$ You're welcome. $\endgroup$
    – Mr.Wizard
    Commented Sep 4, 2013 at 11:09


Browse other questions tagged or ask your own question.