The waves in the legend are out of order.

When I execute a legend command, all my waves are out of order in the legend.

I understand that this depends on the order that the waves were loaded into the program.

Is there an alternative to IndexedFile($pathName, index, "????") that would return waves in an abc# order? Or will I have to reorder the list on my own?

For example, currently Print IndexedFile($pathName,-1,"????") returns
il040904_4.txt;
il040904_1.txt;
il040904_2.txt;
il040904_3.txt;
il040904_9.txt;
il040904_8.txt;
il040904_5.txt;
il040904_10.txt; etc

 Function LoadYWavesFromFolder(pathName)
    String pathName  
   
        //get file path
    if (strlen(pathName) == 0)
        NewPath/O/M="Choose a folder containing dat files. . . " IndexedFilePath
        if (V_flag != 0)
            return -1               // User cancelled
        endif
        pathName = "IndexedFilePath"
    endif

    Variable index = 0
   
    do
        String fileName = IndexedFile($pathName, index, "????")
        if (strlen(fileName) == 0)
            break           // No more files.
        endif
           
        LoadWave/J/D/O/Q/K=1/L={0,0,0,1,1}/N=temp/P=$pathName fileName
       
            //parsing filename
        if (V_flag > 0)
            String name = StringFromList(0,  S_waveNames)
            Wave w = $name
               
            String tempName = S_fileName       
            tempName = ParseFilePath(3, S_fileName, ":", 0, 0)    // Copy basename
            tempName = LowerStr(tempName)
            String extension = ParseFilePath(4,S_filename,":",0,0)  // Copy extension
            extension = LowerStr(extension)
            String desiredName
                   
            desiredName = tempName + "_" + extension + "y"
                   
            if (Exists(desiredName) != 0)
                desiredName =  UniqueName(desiredName, 1, 0)
            endif
            Rename w, $desiredName             
        endif
        index += 1
    while (1)
    printf ":: Done Loading\r"
        return 0
End
Quote:
Is there an alternative to IndexedFile($pathName, index, "????") that would return waves in an abc# order? Or will I have to reorder the list on my own?


The order in which IndexedFile returns the files depends on the operating system.

You can sort the list and process the files in sorted order like this:
Function Demo()
    String pathName = "Igor"
    String list
   
    list = IndexedFile($pathName, -1, ".txt")
    list = SortList(list, ";", 16)          // Sort wave9 before wave10
   
    Variable numItems = ItemsInList(list)
    Variable i
    for(i=0; i<numItems; i+=1)
        String fileName = StringFromList(i, list)
        Print i, fileName
    endfor
End

I made a mistake, which I have now corrected, in my post above.

I wrote this:
    list = SortList(list, ";", 2)           // Numeric sort


I should have written this:
    list = SortList(list, ";", 16)          // Sort wave9 before wave10


To see the difference, execute:
Print SortList("File1.txt;File10.txt;File2.txt;", ";", 2)   // Numeric sort
Print SortList("File1.txt;File10.txt;File2.txt;", ";", 16)  // Sort wave9 before wave10


This prints:
File1.txt;File10.txt;File2.txt;     // Numeric sort (options = 2)
File1.txt;File2.txt;File10.txt;     // Sort wave9 before wave10 (options = 16)


The examples for SortList show that the numeric sort (2) is intended for when the list contains only numbers while the other one (16) is intended for cases like yours where you have a name followed by a number and you want the number to be treated numerically rather than alphabetically in the sort if the name for two items is the same.