Load n files from a directory

Hi All,

I would like to load a serie of binary images and assign the name of the file each. Reading the forum I found a function and I modified it:

Function load()

NewPath myPath
String name,list=IndexedFile(myPath, -1, ".dat")

Variable i,numFiles=ItemsInList(list,";")

for(i=0;i<numFiles;i+=1)
name=StringFromList(i,list)
GBLoadWave/O/T={16,16}/S=393/W=1/P=myPath name
//ImageLoad/T=TIFF/P=myPath name
endfor
End

I use the comand GBLoadWave but I don't know how I can use a variable (i) or a string (name) like a wave name.

Thanks,

MatLey

GBLoadWave creates two local variables:
S_waveNames -- semicolon separated list of names of loaded waves
S_fileName -- name of file loaded (such as "file1.dat")

You can use these to get a reference to the loaded wave and rename it to the same name as the file. See modifications to your function.


Function load()
	NewPath myPath
	String name,list=IndexedFile(myPath, -1, ".dat")
	String LoadedWaveName
	String FileName
	Variable i,numFiles=ItemsInList(list,";")
	
	for(i=0;i<numFiles;i+=1)
		name=StringFromList(i,list)
		GBLoadWave/O/T={16,16}/S=393/W=1/P=myPath name
		LoadedWaveName = StringFromList(0,S_waveNames)	//name assigned to image by GBLoadWave
		FileName = RemoveEnding(S_fileName, ".dat")	// name of file loaded minus ".dat" extension
		Wave w = $LoadedWaveName	//get reference to wave loaded by GBLoadWave
		Rename w, $FileName	//rename the loaded wave to file name
		//ImageLoad/T=TIFF/P=myPath name
	endfor
End


The "$" operator seems to be what you were looking for. Type: DisplayHelpTopic "Converting a String into a Reference Using $" into the command line to see more about it.