A DataFolderList function?

Does IP9 by chance have this function?

DataFolderList(matchStr,separatorStr,[optionsStr])

If not, would you please consider adding it. I keep tripping up trying to roll my own to parse through data folders for popups or for batch processing operations.

Hi,

This function exists:

DataFolderDir(mode [, dfr ] )
The DataFolderDir function returns a string containing a listing of some or all of the objects contained in the current data folder or in the data folder referenced by dfr .

mode  is a bitwise flag for each type of object. Use -1 for all types.
Type    Bit Number    Bit Value
All        -1
Data Folders    0    1
Waves    1    2
Numeric Variables    2    4
String Variables    3    8
dfr  is a data folder reference.

 

It does not have match string in your request, but it does have the option to look beyond the current data folder which is nice.

You could post process the list to get the sing match functionality.

Andy

DataFolderDir is cumbersome (and even the instructions in the IP8 manual hint as much). I really want an equivalent to WaveList or ImageList or VariableList or StringList with the match string ... so that I can simply do this:

string FolderstoProcess = DataFolderList("rp*",";") -- get string list of data folders in current direction

Hi,

I find your comment about it being cumbersome as odd coming from someone which such prowess in Igor programming.

Would this work for you?

Function/S DataFolderlist(String inputstr, String Seperator)

    string thelist
    thelist = dataFolderDir(1)
    //Remove the "FOLDERS"
    thelist = ReplaceString("FOLDERS:", thelist, "")
    variable index,maxindex
    maxindex=itemsInList(thelist,",")-1 //Working backwards on list so need to start at end
    for(index=maxindex;index>=0;index-=1)
        If(stringmatch(StringFromList(index, thelist , ","),inputstr)==0)//no match to inputstr
            thelist = RemoveListItem(index, thelist ,",")
        endif
    endfor
    //switch out seperator
    thelist = ReplaceString(",", thelist, seperator)
    thelist = ReplaceString(";", thelist, seperator) //the initial string has a terminal ;
    return thelist
   
end

Andy

Thanks for the compliment and the code.

Unfortunately, prowess only goes so far when you've buried the code from a year or so ago in some obscure location and now have to rack your brain trying to remember how to reconstruct it using wildcard strings and doing so within the next hour so that you can generate a package for your graduate student who needs to be one step further to completing his dissertation defense in a few weeks.

And then you see WaveList and VariableList and StringList and ... OMG!!! Why do we not have a DataFolderList function too???

It is this in terms of being cumbersome.

Function/S DataFolderList()
 
    String topFolder= GetDataFolder(1)
    String itemList =""
 
    Variable i,n= CountObjects(topFolder, 4)
    for(i=0; i<n; i+=1 )
        String fName = GetIndexedObjName(topFolder, 4, i)
        itemList += fName+";"
    endfor
    return itemList
End

Function/S MatchingDataFolderList(String matchThis)
 
    String topFolder= GetDataFolder(1)
    String itemList =""
 
    Variable i,n= CountObjects(topFolder, 4)
    for(i=0; i<n; i+=1 )
        String fName = GetIndexedObjName(topFolder, 4, i)
        if( StringMatch(fName,matchThis) )
            itemList += fName+";"
        endif
    endfor
    return itemList
End

 

After a nights sleep, a brisk walk, and a bit of coffee, cumbersome should be replaced with "a bit frustrating". I appreciate the code. I remain hopeful that we can eventually have a built-in function.

In reply to by jjweimer

jjweimer wrote:

...Why do we not have a DataFolderList function too???

 

About a week ago I thought exactly the same!

There are at least two users who greatly appreciate the addition to IP9 ;-)

Thanks!