int fb_ls_ext(const char *ext){
	int CurrentNavId = -1;

	// if no navigator available, return an error
	if ((CurrentNavId = fsaccess_alloc_nav_id()) < 0) return ERROR_NO_NAV_ID;

	// select the navigator
	nav_select( CurrentNavId );

	// navigate to folder
    if(nav_setcwd((FS_STRING)currentDirectory, FALSE, FALSE) == FALSE){
    	fsaccess_free_nav_id(CurrentNavId);
    	return ERROR_NOT_A_DIRECTORY;
    }
    if(nav_filelist_first(FS_FILE)==FALSE){
    	fsaccess_free_nav_id(CurrentNavId);
    	return ERROR_UNKNOWN;
    }
    char filename[255];
    if(nav_file_getname(filename,sizeof(filename))==FALSE){
    	fsaccess_free_nav_id(CurrentNavId);
    	return ERROR_UNKNOWN;
    }


    seprintf("Contents of folder %s:\n\n",currentDirectory);

    nav_filelist_single_enable( FS_DIR );
    int filecount = nav_filelist_nb(FS_DIR);

    short a;
    for(a=0; a < filecount; a++){
    	if(nav_filelist_goto(a)==FALSE)return ERROR_UNKNOWN;
        char filename[255];
        if(nav_file_getname(filename,sizeof(filename))==FALSE){
        	fsaccess_free_nav_id(CurrentNavId);
        	return ERROR_UNKNOWN;
        }

        seprintf("%d: %s\n",a,filename);
    }
    nav_filelist_single_enable( FS_FILE );
    filecount = nav_filelist_nb(FS_FILE);
    for(a=0; a < filecount; a++){
    	if(nav_filelist_goto(a)==FALSE)return ERROR_UNKNOWN;
    	if(!nav_file_checkext(ext))continue;
        char filename[255];
        if(nav_file_getname(filename,sizeof(filename))==FALSE){
        	fsaccess_free_nav_id(CurrentNavId);
        	return ERROR_UNKNOWN;
        }

        seprintf("%d: %s\n",a,filename);
    }

    fsaccess_free_nav_id(CurrentNavId);
    return 0;
}
int fb_iterator_has_next(){
    if(iterator_index>=filecount)return 0;

    int a = iterator_index;

    while(1){
    	if(a==filecount)return 0;
    	if(nav_filelist_goto(a++)==FALSE)return 0;
    	if(!nav_file_checkext(ext))continue;
    	return 1;
    }
}
int fb_iterator_seek(int i){
	if(i>=filecount) return ERROR_INDEX_OUT_OF_BOUNDS;
	if(i<0) return ERROR_INDEX_OUT_OF_BOUNDS;
	int j = 0;
	while(i>=0 && j<filecount){
		nav_filelist_goto(j++);
		if(nav_file_checkext(ext))i--;
	}
	j--;

	//Seeker reached end of directory without successfully seeking i files
	//with file extension ext.
	if(i>=0)return ERROR_INDEX_OUT_OF_BOUNDS;
	iterator_index = j;
	return 0;
}
Example #4
0
//! This function goes to the previous position in filtered file list
//!
//! @return    false in case of an error or no next file, see global value "fs_g_status" for more detail
//! @return    true otherwise
//!
bool  nav_filterlist_previous( void )
{
   uint16_t u16_current_pos;
   u16_current_pos = nav_filelist_get();
   while( nav_filelist_set( 0, FS_FIND_PREV ) )
   {
      if( nav_file_isdir()
      ||  nav_file_checkext( fs_g_nav.sz_filterext ) )
      {
         fs_g_nav.u16_pos_filterlist--;
         return true;
      }
   }
   nav_filelist_goto( u16_current_pos );
   return false;
}
char *fb_iterator_next(){


    static char filename[255];

	while(1){
		if(iterator_index==filecount){
			return NULL;
		}
		if(nav_filelist_goto(iterator_index++)==FALSE){
			return NULL;
		}
    	if(!nav_file_checkext(ext))continue;
    	if(nav_file_getname(filename,sizeof(filename))==FALSE){
    		return NULL;
    	}
    	return filename;
	}
}
Example #6
0
//! This function goes to the next position in the filtered file list
//!
//! @return    false in case of error or no next file, see global value "fs_g_status" for more detail
//! @return    true otherwise
//!
bool  nav_filterlist_next( void )
{
   uint16_t u16_current_pos;
   u16_current_pos = nav_filelist_get();
   while( nav_filelist_set( 0, FS_FIND_NEXT ) )
   {
      if( nav_file_isdir()
      ||  nav_file_checkext( fs_g_nav.sz_filterext ) )
      {
         if( FS_NO_SEL == u16_current_pos )
         {
            fs_g_nav.u16_pos_filterlist = 0;
         }else{
            fs_g_nav.u16_pos_filterlist++;
         }
         return true;
      }
   }
   nav_filelist_goto( u16_current_pos );
   return false;
}