Duplicate variables (or strings) from one data folder to another
I want to duplicate a set of variables created at root: into a DataFolder existing at the root level. I came up with the code below (IP9). The two calls to SetDataFolder root: are safety redundancies.
string theItem, theSItem
SetDataFolder root:
wave/T varList = ListtoTextWave(VariableList("tau*",";",4) + VariableList("UB*",";",4),";")
SetDataFolder root:dataStore
for(theItem : varList)
theSItem = "root:" + theItem
NVAR tv = $theSItem
variable/G $theItem = tv
endfor
SetDataFolder root:Essentially, I have to a) collect the variable list at root, b) move to the storage data folder, c) iterate over the variable list to ci) reference the root: variable using NVAR and cii) generate the new variable using variable/G.
Does a more elegant way exist to duplicate variables (and strings)?
You could group them in a datafolder and use DuplicateDataFolder.
May 6, 2026 at 10:38 am - Permalink
Just curious. How is it possible to "group them in a data folder" (programmatically) without something akin to the above?
In the meantime, I'm refactoring to store strings and variables in a root-level data folder at the outset (followed by DuplicateDataFolder).
And in the meantime, I would have wished to have raised my hand last year or so with IP10 for DuplicateVariable and DuplicateString commands (or Move.../D flag for "duplicate" rather than just move).
May 6, 2026 at 04:27 pm - Permalink
This code is arguably slightly cleaner:
I don't see how a DuplicateVariable or DuplicateString command would make this easier.
May 7, 2026 at 06:00 am - Permalink