Load all files in a directory


//This function automatically loads all files in a folder that the user selects. In this instance, the function
//assumes that each file is a Dionex Chromeleon generated ASCII file, and that the chromatogram's data
//points were collected at 0.2 sec. intervals. You MUST must make the changes appropriate to your data
//files on the lines below marked with exclamation points!!!
function loader()
	//initialize loop variable
	variable i=0
	string wname,fname            //wave names and file name, respectively
	
	//Ask the user to identify a folder on the computer
	getfilefolderinfo/D
	
	//Store the folder that the user has selected as a new symbolic path in IGOR called cgms
        //!!!!!!!!! if you prefer a different name, change ALL instances of cgms in the function !!!!!!!!
	newpath/O cgms S_path

	//Create a list of all files that are .txt files in the folder. -1 parameter addresses all files.
       // !!!!!!!!! if your files have a different extension, change .TXT below to your extension!!!!!!!!!!!!
	string filelist= indexedfile(cgms,-1,".TXT")

	//Begin processing the list
	do
		//store the ith name in the list into wname.
		fname = stringfromlist(i,filelist)

		//strip away ".txt" to get the name of the chromatogram, which is the file name
                //!!!!!!!!!! change the next line if you want a different name for the waves that are created !!!!!!!!!!!!!!!
		wname = fname[0,strlen(fname)-5]

		//reference a wave with the name of the chromatogram.
		wave w = $wname
		
		//if the referenced wave does not exist, create it.
		if (!waveexists(w) )

			//The /L parameter tells IGOR to load no headers, and to load the 3rd column of data (indexed as 2) only
                        //!!!!!!!! You must change this next line to tell IGOR how to load the data in each file !!!!!!!!!!!!!!!
			LoadWave/G/D/A=wave/P=cgms/O/L={0,0,0,2,0} stringfromlist(i,filelist)

			//wave created is wave0. It is renamed after the chromatogram.
			rename wave0 $wname

			//And scaled accordingly.
                        //!!!!!!!!! you MUST change or delete the following line according to your data's scaling or lack thereof. !!!!!!!!!!!!
			setscale/P x,0,0.0033333,$wname
			//Print confirmation of what was just loaded.
			print 	"Loaded "+fname

		else 
			//Othewise, tell the user that this chromatogram was previously loaded.
			print 	fname+" was previously loaded. Its corresponding wave exists."
		endif
		i += 1  		//move to next file
	while(i<itemsinlist(filelist)) 			//end when all files are processed.
end
FileLoader_1.ipf (2.53 KB)

Forum

Support

Gallery

Igor Pro 10

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More