# Using a variable in Get [duplicate]

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.

• 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]) – Mr.Wizard Sep 4 '13 at 10:55
• Thanks, that works. Can you explain though why it works? The other answer which you directed me to I don't understand at all. – lara Sep 4 '13 at 11:02
• 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. – Mr.Wizard Sep 4 '13 at 11:07
• Oh ok thanks, that is the short and sweet answer which I do understand. Thanks so much. – lara Sep 4 '13 at 11:07
• You're welcome. – Mr.Wizard Sep 4 '13 at 11:09