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_init(Bool type){ file_or_dir = type; fb_iterator_reset(); // if no navigator available, return an error if ((iterator_navid = fsaccess_alloc_nav_id()) < 0) return ERROR_NO_NAV_ID; fsaccess_take_mutex(); // select the navigator nav_select( iterator_navid ); // navigate to folder if(nav_setcwd((FS_STRING)currentDirectory, FALSE, FALSE) == FALSE){ fsaccess_free_nav_id(iterator_navid); return ERROR_NOT_A_DIRECTORY; } //select top of list if(nav_filelist_first(type)==FALSE){ fsaccess_free_nav_id(iterator_navid); return ERROR_UNKNOWN; } nav_filelist_single_enable( type ); filecount = nav_filelist_nb(file_or_dir); return 0; }
//! This function computes the number of files and/or directories in filtered file list //! This function is not blocking. It will return after \<retry\> iteration if the result //! is not yet computed. //! //! @param fl_type FL_ALL To check all types (files and directories). <br> //! FL_DIR To check the directory presence. <br> //! FL_FILE To check the file presence. //! //! @param sz_filterext Extension filter (ASCII format, e.g.: "txt" or "txt,d*,wk" ). <br> //! If this argument in NULL, then it uses the default filter used by the filterlist. <br> //! This argument is also ignored for b_type == FS_DIR. //! @param p_total Pointer to the result which will be updated by the function (added). //! Initialization shall be done before entering into this function. //! @param retry Number of files seen before leaving the function. 0 means that the //! function is blocking until the result is known. //! //! @return number of files and/or directories present in filtered file list. //! bool nav_filterlist_nb_ex( fl_type_t fl_type, const FS_STRING sz_filterext, uint16_t* p_total, uint8_t retry ) { static uint16_t u16_save_position; bool b_is_dir; // save current position if( *p_total==(uint16_t) -1 ) { u16_save_position = fs_g_nav.u16_pos_filterlist; // Reset position if ( !nav_filterlist_reset()) return true; if (fl_type == FL_DIR) nav_filelist_single_enable(FS_DIR); else if (fl_type == FL_FILE) nav_filelist_single_enable(FS_FILE); *p_total = 0; } // Scan all while( nav_filelist_set( 0, FS_FIND_NEXT ) ) { b_is_dir = nav_file_isdir(); // Check if its a file for FL_FILE mode if (fl_type == FL_FILE && b_is_dir) { if (!update_counter(&retry)) return false; continue; } // Check if its a directory for FL_DIR mode if (fl_type == FL_DIR && !b_is_dir) { if (!update_counter(&retry)) return false; continue; } // If the selection is on a file if (!b_is_dir) { // Check the extension of the file if (!((sz_filterext)?nav_file_checkext(sz_filterext):nav_file_checkext(fs_g_nav.sz_filterext))) if (!update_counter(&retry)) return false; } (*p_total)++; if (!update_counter(&retry)) return false; } nav_filelist_single_disable(); // Restore previous position if ( u16_save_position != FS_NO_SEL ) { nav_filterlist_reset(); }else{ // After operation, there are a file selected nav_filterlist_goto( u16_save_position ); } return true; }