WaveList based on a range of number

Dear all,

I'd like to make (and display) a list of waves based on the range of integers (suffix) in the wave name:

say, the names of my waves are as follows: "test_a4_350", "test_a4_351", "test_a4_352", ..., "test_a4_850".

How can I make a list of wavenames that includes only waves from "test_a4_380" to "test_a4_450"?

Thanks very much!
The following code is not very elegant, but should do the job. Following your example, call it using

ListOfWaves(380, 450)

to get a string list of wave names ending in values from 380 to 450 and including the end points.

//vMin & vMax are the min and max suffix values marking wave names to retain
//outputs a string list (semicolon separated) of wave names with suffixes matching vMin & vMax
Function/S ListOfwaves(vMin, vMax)
    Variable vMin
    Variable vMax
   
    Variable vIndex = 0
    Variable vSuffix = 0
    Variable vNumItems = 0
    Variable vStrLength
    String sFullList = ""
    String sEditedList = ""
    String sListItem = ""
   
    sFullList = WaveList("*", ";", "" )
    vNumItems = ItemsInList(sFullList, ";")
    for( vIndex = 0; vIndex < ItemsInList(sFullList, ";"); vIndex += 1)
        sListItem = StringFromList(vIndex, sFullList, ";")
        vStrLength = strlen( sListItem )
        vSuffix = str2num( sListItem[vStrLength - 4, vStrLength - 1] )
        if( vSuffix >= vMin && vSuffix <= vMax)
            sEditedList += sListItem + ";"
        endif
    endfor
    return sEditedList
End
//vMin & vMax are the min and max suffix values marking wave names to retain
//outputs a string list (semicolon separated) of wave names with suffixes matching vMin & vMax
Function/S ListOfWaves(baseName, vMin, vMax)
    String baseName
    Variable vMin, vMax
   
    Variable vIndex = 0
    String sEditedList = "", sListItem
 
    for( vIndex = vMin; vIndex <= vMax; vIndex += 1)
        sprintf sListItem, "%s%d", baseName, vIndex
        if (exists(sListItem) == 1)
            sEditedList += sListItem + ";"
        endif
    endfor
    return sEditedList
End


ListOfWaves("test_a4_", 380, 450)
Dear jtigor and kanekaka,

Your codes definitely solved my problem! Thanks so much for your generosity and wisdom. I also learned a bit about how to optimize my igor code from reading yours.

xhou,

One other thing to keep in mind is that both functions operate only on the current folder.

I like kanekaka's solution... a good example of thinking outside the box.