DataFolder Programming, Movewave PathName help

Hi All,

I was hoping someone could help me with where I'm going wrong in this procedure.

I have a Parent Data Folder with maybe 9 or 10 subdatafolders inside it. (NOTE Parent data folder is itself a subfolder in something else.)

In each data folder there is a 2D wave which i would like to duplicate and then move the duplicate 2D wave to a new data folder that is located in the Parent Data Folder.
Fortunately I only have one 2D matrix in each subfolder beginning with a r so I can fileter it out using wavelist.

I wrote this to try and achieve this:


Function ExtractMatrices(ParentDF)
	DFREF ParentDF
	
	 ListFolders() // function that returns a string of the folders contained in the ParentDataFolder similar to wavelist
	 SVAR FolderListStr
	 Variable numItems = ItemsInList(FolderListStr), i // counts how and indices the item broken by ;
	 
	 NewDataFolder/O ParentDF:Matrix_Copies
	
	for (i = 0; i<numItems; i+=1) // starts a loop to go through each name
		String DFname = StringFromList(i,FolderListStr,";") 
		SetDataFolder DFname
			String findMatrix=Wavelist("r*",";","") 
			String matrix= StringFromList(0,findMatrix,";")
			wave mat2D = $matrix
			String DuplicateWaveName= Nameofwave(mat2D)+"_D"
			duplicate/O mat2D, mat2D_D
			rename mat2D_D, $DuplicateWaveName
			movewave mat2D_D, :ParentDF:Matrix_Copies:
		SetDataFolder ParentDF
	endfor
End


Problem 1) I don't think I've quite cracked the best way to reference a path name because when I first tried this function I accidentally had the arrow on the databrowser selecting a subfolder and the function would create the new folder in that data set ignoring what I had written.

Problem 2) Going deeper inside a datafolder seems simple enough but trying to step back out I am having problems. As when I run it I manage to duplicate the first wave but I can't extract it out.


I think i'm missing a few fundamental concepts here through lack of experience so if anyone can help that would be great!

Best wishes,

N
You are right that there is no straight-forward way to get a reference to the parent data folder of a given data folder.

Here is a solution:


Function DupWaveToParentDataFolder(w)
	Wave w

	String dfPath = GetWavesDataFolder(w, 1)			// Full path without wave name
	if (CmpStr(dfPath, "root:") == 0)
		return -1	// Error: wave is in root data folder
	endif
	
	String parentDFPath = dfPath + ":"					// "::" at the end backs up one level
	DFREF parentDFR = $parentDFPath
	
	String name = NameOfWave(w)
	Duplicate/O w, parentDFR:$name
	
	return 0
End