Loading multiple waves from multiple .txt files

What I'd like to do is to be able to select multiple .text files and load in two waves from each (1st and 3rd columns). 'Open' lets me select multiple files but then once the for loop starts, it opnes 3 more windows for me to select files. I was hopeing LoadWave would load the first column in each file in 'loadedFiles' as t0, t1, t2, etc. and the third column as c0, c1, c2, etc.

On paper, I'd say this code would do that but LoadWave opens a new file selection window every time it loops. I thought StringFromList(i, loadedFiles) would load the full path name of the file of interest which would negate the need for a selection window. Where is my misunderstanding in this?


Function loadMult()
    variable RefNum
    String message = "Select one or more files"
    String fileName
    String fileFilters = "Data Files (*.txt,*.dat,*.csv):.txt,.dat,.csv;"
    fileFilters += "All Files:.*;"
    Open /D /R /MULT=1 /F=fileFilters /M=message refNum
        Print "The RefNUM is: ", refNum
        String loadedFiles = S_fileName
        Print loadedFiles[1]
        Print "The Selected Files are: ", loadedFiles

    if (strlen(loadedFiles) == 0)
        Print "File Contains No Data - Script was Cancelled!!"
        Variable numFilesSelected = ItemsInList(loadedFiles, "\r")
            Variable i
            for(i=0; i<numFilesSelected; i+=1) 
                String columnInfoStr = ""
                columnInfoStr += "N=t" + num2str(i) + ";"
            columnInfoStr += "C=1,N='_skip_';"   // Skip Column1
            columnInfoStr += "N=c" + num2str(i) + ";"
            LoadWave/J/D/O/L={0,1,0,0,3}/B=columnInfoStr StringFromList(i, loadedFiles) //This opens more dialog windows
        return 0      


In reply to by Jakub

Jakub wrote:
The loadwave fails to find the directory and filename somehow... Why is that happening?

LoadWave needs to know the name of the file and the folder containing the file.

The use of "StringFromList(i, loadedFiles)" makes it difficult to debug this. Store the output from StringFromList in a local string variable and print it to the history or use the debugger to inspect it.

loading 1st and 3rd columns sounds a bit like something I have had to do before. maybe this procedure contains something useful?