Read File Contents into String Variable

This function shows how to read the entire contents of a file into a string variable. This is sometimes useful, for example, to search for a particular character in the file or quickly count the number of lines.

Function/S ReadFileIntoString(pathName, filePath)
	String pathName		// Name of Igor symbolic path. Can be "" if filePath is a full path.
	String filePath			// File name, path relative to pathName, or full path
	
	Variable refNum
	Open/R/P=$pathName refNum as filePath
	
	FStatus refNum
	Variable numBytes = V_logEOF
	
	String data = PadString("", numBytes, 32)
	FBinRead refNum, data
	
	Close refNum
	
	return data
End

Forum

Support

Gallery

Igor Pro 10

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More