src/Utilities.cpp
std::list<std::string> GetDirContents (const std::string& path)
{
    std::list<std::string> l;               // the list to be returned
    char szNames[4048];                     // buffer for file names
    char* indices[256];                     // buffer for indices to beginnings of names
    int start = 0;                          // first file to return
    int numFiles = 0;                       // number of files returned (per batch)
    bool bFinished = false;
    
    // Call XPLMGetDirectoryContents as often as needed to read all directory content
    do {
        numFiles = 0;
        bFinished = XPLMGetDirectoryContents(path.c_str(),
                                             start,
                                             szNames, sizeof(szNames),
                                             indices, sizeof(indices)/sizeof(*indices),
                                             NULL, &numFiles);
        // process (the batch of) files we received now
        for (int i = 0; i < numFiles; ++i)
            if (indices[i][0] != '.')           // skip parent_dir and hidden entries
                l.push_back(indices[i]);
        // next batch start (if needed)
        start += numFiles;
    } while(!bFinished);
    
    // return the list of files
    return l;
}
// List of files in a directory (wrapper around XPLMGetDirectoryContents)
List of files in a directory (wrapper around XPLMGetDirectoryContents)
List of files in a directory ( wrapper around XPLMGetDirectoryContents )
std::list<std::string> GetDirContents (const std::string& path)
{
    std::list<std::string> l;               
    char szNames[4048];                     
    char* indices[256];                     
    int start = 0;                          
    int numFiles = 0;                       
    bool bFinished = false;
    do {
        numFiles = 0;
        bFinished = XPLMGetDirectoryContents(path.c_str(),
                                             start,
                                             szNames, sizeof(szNames),
                                             indices, sizeof(indices)/sizeof(*indices),
                                             NULL, &numFiles);
        for (int i = 0; i < numFiles; ++i)
            if (indices[i][0] != '.')           
                l.push_back(indices[i]);
        start += numFiles;
    } while(!bFinished);
    return l;
}
std :: list < std :: string > GetDirContents ( const std :: string & path ) { std :: list < std :: string > l ; char szNames [ 4048 ] ; char * indices [ 256 ] ; int start = 0 ; int numFiles = 0 ; bool bFinished = false ; do { numFiles = 0 ; bFinished = XPLMGetDirectoryContents ( path . c_str ( ) , start , szNames , sizeof ( szNames ) , indices , sizeof ( indices ) / sizeof ( * indices ) , NULL , & numFiles ) ; for ( int i = 0 ; i < numFiles ; ++ i ) if ( indices [ i ] [ 0 ] != ' ' ) l . push_back ( indices [ i ] ) ; start += numFiles ; } while ( ! bFinished ) ; return l ; }
List of files in a directory (wrapper around XPLMGetDirectoryContents)
List of files in a directory ( wrapper around XPLMGetDirectoryContents )
// the list to be returned // buffer for file names // buffer for indices to beginnings of names // first file to return // number of files returned (per batch) // Call XPLMGetDirectoryContents as often as needed to read all directory content // process (the batch of) files we received now // skip parent_dir and hidden entries // next batch start (if needed) // return the list of files