Help with User-Defined Trace Names

In Igor Pro 10.01, I am trying to provide user-defined names for traces but running into issues. Specifically, I would like to name the trace as the name of the data folder that it is in. However, when I execute the following code in the data folder with path root:dir1, It makes a graph with the trace literally named "dataFolderName" instead of "dir1". 

string dataFolderName
dataFolderName = GetDataFolder(0)
display absorbance/TN=dataFolderName vs energy_eV

If I instead execute the following, I get an "expected keyword or name" error at the first parenthesis

display absorbance/TN=(GetDataFolder(0)) vs energy_eV

or a "syntax error" at the first parenthesis for the following.

display absorbance/TN=GetDataFolder(0) vs energy_eV

Even if I try to manually enter the name as "dir1", I get an "expected keyword or name" error at the quotation mark:

display absorbance/TN="dir1" vs energy_eV

I am only successful in renaming the trace dir1 with one of the following:

display absorbance/TN=dir1 vs energy_eV
display absorbance/TN='dir1' vs energy_eV

However, the goal is to automate the naming of traces as the name of their data folder by executing a few lines of code on the command line in the relevant data folder. 

As a note, this issue occurs with or without the vs Xwave

Why does the /TN flag not take a string as an input? Is there another way I can achieve my goal of renaming the trace as the data folder of the wave?

jjweimer
Use /TN=$datafolderName in your first case. For improved reliability, also consider setting datafolderName = CleanUpName(GetDataFolder(0)...).
Ben Murphy-Baum

The /TN flag accepts a 'name', which is distinct from a 'string'. A name would be the unquoted literal text provided to the flag, this is why /TN=dir1 is accepted but /TN="dir1" is not. You can do what you want by using the $ operator to convert the string to a name, like this:

display absorbance/TN=$dataFolderName vs energy_eV

That syntax with $dataFolderName is telling Igor's compiler to use the value of the string as a name. There are a fair number of operations in Igor that expect names instead of strings, so you have to keep this in mind sometimes. A common example of using the $ operator is when you have a string and you want to use it to define the name of a wave that you're going to make:

String theName = "mywave_0"
Make $theName  // Creates a wave called 'mywave_0'