Load n files, specifying first file

Hi all,

I have written a procedure, which I will be implementing in a GUI, where n image files are loaded. The number of images (n) is already determined by the length of a pre-existing wave. The user selects the first file in the list from a dialogue, the script then loads all the waves. My approach was to select the first file, then generate a list of all the files in the folder using IndexedFile(myPath, -1, "TIFF"), get the index of the first file selected using WhichListItem then loop to generate a list of all the required files. I wanted to this so that I could call the ImageLoad operation just once operating on the list of selected files. The problem however, is that with the path name and a list of up to, or even greater than 20 images with 20 characters per name the strings quickly become too long. I know that this can be solved by just putting the image load in the loop selecting the files but is there any way to initiate the ImageLoad once (Would it even be quicker or worthwhile!?) or should I just stick it in the loop and call for each file? See the code below:

Function LoadAllimagesFromScan()
    String pathName = ""
    String fileName = ""
   
    Open/D/R/T="TIFF" /P=$pathName /M="Select first image in scan" refNum as fileName
    If ( strlen(S_fileName) == 0 )
        return -1
    endif
   
    pathName = ParseFilePath(1, S_fileName, ":", 1, 0)
    NewPath/O myPath pathName
    fileName = ParseFilePath(0, S_fileName, ":", 1, 0)
   
    String FilesInFolder = IndexedFile(myPath, -1, "TIFF")
    Variable firstFileIndex = WhichListItem(fileName, FilesInFolder)
   
    Wave wAlphaI = $(StringFromList(0,WaveList("*","","DIMS:1")))  // there is only one wave in this folder with Dim = 1
   
    String filesToLoad = ""
    Variable fileIndex = firstFileIndex    
    Do
        filesToLoad += IndexedFile(myPath, fileIndex, "TIFF")+";"
               
        if( strlen(fileName) == 0 )
            break
        endif
   
        fileIndex += 1
    While( fileIndex < firstFileIndex+(NumPnts(wAlphaI) )
   
    String ImageLoadCMD
    sprintf ImageLoadCMD, "ImageLoad/P=%s/T=TIFF %s" , pathName, filesToLoad
    Execute ImageLoadCMD
   
End


Thanks,

Tom
Hello Tom,

ImageLoad is designed to handle one image file per call. Here is an example of loading all images in a folder specified by the user (Newpath) and where the file names have the suffix ".tif":

Function load()

    NewPath myPath
    String name,list=IndexedFile(myPath, -1, ".tif")
    Variable i,numFiles=ItemsInList(list,";")
   
    for(i=0;i<numFiles;i+=1)
        name=StringFromList(i,list)
        ImageLoad/T=TIFF/P=myPath name
    endfor
End


I hope this helps,

A.G.
WaveMetrics, Inc.