
Load All Files From Folder - Assumes each file contains one column of numbers


hrodstein
#pragma rtGlobals=3 // Use modern global access method and strict wave access. Menu "Load Waves" "Load All Files From Folder", LoadAllFilesFromFolder("", ".txt") End // LoadAllFilesFromFolder(pathName, extension) // // This function loads each file in a given file folder into Igor as general text. // NOTE: Each file is assumed to contain one column of numbers. // // pathName is the name of an Igor symbolic path or "" to get a dialog. // The name of each data file is assumed to end with the specified file name extension. // The output wave name is the file name less the extension. // // NOTE: You may need to change the LoadWave command to fit your file format. // Use Data->Load Waves->Load Waves to find the right command and then adjust the LoadWave command below. Function LoadAllFilesFromFolder(pathName, extension) String pathName // Name of an Igor symbolic path or "" to get a dialog String extension // File name extension - e.g., "txt" or ".dat" if (strlen(pathName) == 0) NewPath/O/M="Choose a folder containing data files" DataFilesPath if (V_flag != 0) return -1 // User cancelled endif pathName = "DataFilesPath" endif Variable numFilesLoaded = 0 String fileName Variable index index = 0 do fileName = IndexedFile($pathName, index, extension) if (strlen(fileName) == 0) break // No more files. endif String wName = ParseFilePath(3, fileName, ":", 0, 0) // Remove extensions wName = CleanupName(wName, 0) // Make legal standard Igor wave name Variable existsCode = exists(wName) if (existsCode!=0 && existsCode!=1) // wName conflicts with some name other than a wave name so make it unique wName = UniqueName(wName, 1, 0) endif String columnInfoStr sprintf columnInfoStr, "N='%s';", wName LoadWave/G/D/P=$pathName/A/O/B=columnInfoStr/Q fileName Wave w = $wName // Create a wave reference // Do something with w if you wish numFilesLoaded += 1 index += 1 while (1) Printf "Loaded %d files\r", numFilesLoaded End

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More