/********************************************* *@brief 在文件夹中遍历子文件,记录文件大小信息 *@param [in ] directory_path *@param [out] directory_name *@param [in ] pattern 匹配模式,比如“*.fsn” *@return ********************************************** */ static int traverse_subfile(char *file_path, sd_file_manage_t *p_sd_file_manage, char *pattern) { int res; DIR directory_object; FILINFO file_object; #if _USE_LFN char lfn[_MAX_LFN + 1]; file_object.lfname = lfn; file_object.lfsize = _MAX_LFN + 1; #endif res = f_findfirst(&directory_object, &file_object, file_path, pattern); while (res == FR_OK && file_object.fname[0]) { #if _USE_LFN DBG_print(DBG_DEBUG, "%-12s %s", file_object.fname, file_object.lfname); #else DBG_print(DBG_DEBUG, "%s", (file_object.fname)); p_sd_file_manage->unload_file_num++; p_sd_file_manage->unload_file_size += file_object.fsize; #endif res = f_findnext(&directory_object, &file_object); } f_closedir(&directory_object); return 0; }
bool findPayload(char *path, u32 pressed) { const char *pattern; if(pressed & BUTTON_LEFT) pattern = PATTERN("left"); else if(pressed & BUTTON_RIGHT) pattern = PATTERN("right"); else if(pressed & BUTTON_UP) pattern = PATTERN("up"); else if(pressed & BUTTON_DOWN) pattern = PATTERN("down"); else if(pressed & BUTTON_START) pattern = PATTERN("start"); else if(pressed & BUTTON_B) pattern = PATTERN("b"); else if(pressed & BUTTON_X) pattern = PATTERN("x"); else if(pressed & BUTTON_Y) pattern = PATTERN("y"); else if(pressed & BUTTON_R1) pattern = PATTERN("r"); else if(pressed & BUTTON_A) pattern = PATTERN("a"); else pattern = PATTERN("select"); DIR dir; FILINFO info; FRESULT result; result = f_findfirst(&dir, &info, "payloads", pattern); if(result != FR_OK) return false; f_closedir(&dir); if(!info.fname[0]) return false; sprintf(path, "payloads/%s", info.fname); return true; }
void ListDir() { F_FIND finder; // location to store the information retreived /* Find first file or subdirectory in specified directory. First call the f_findfirst function, and if file was found get the next file with f_findnext function. Files with the system attribute set will be ignored. Note: If f_findfirst() is called with "*.*" and the current directory is not the root directory, the first entry found will be "." - the current directory. */ volatile int rc = f_findfirst( "*.*", &finder ); if ( rc == F_NO_ERROR ) // found a file or directory { f_getcwd( currDirBuf, CWD_BUFFER_SIZE ); iprintf("\r\n"); iprintf("Current Directory: %s\r\n", currDirBuf); do { if ( ( finder.attr & F_ATTR_DIR ) ) { iprintf( "[%8s/] d\r\n", finder.filename ); } else { iprintf( "%12.12s f %d\r\n", finder.filename, finder.filesize ); } } while ( !f_findnext( &finder ) ); iprintf("\r\n"); } else { iprintf("\r\nError in listing directory\r\n"); } }
/********************************************* *@brief 在文件夹中遍历子文件夹,返回最后文件夹名字指针 *@param [in ] directory_path *@param [out] directory_name *@param [in ] pattern 匹配模式 *@return ********************************************** */ static int traverse_subcatalog(char *directory_path, char *directory_name, char *pattern) { int res; DIR directory_object; FILINFO file_object; #if _USE_LFN char lfn[_MAX_LFN + 1]; file_object.lfname = lfn; file_object.lfsize = _MAX_LFN + 1; #endif res = f_findfirst(&directory_object, &file_object, directory_path, pattern); while (res == FR_OK && file_object.fname[0]) { #if _USE_LFN DBG_print(DBG_DEBUG, "%-12s %s", file_object.fname, file_object.lfname); #else DBG_print(DBG_DEBUG, "%s", (file_object.fname)); #endif strcpy(directory_name, file_object.fname); //TODO: 要优化效率 res = f_findnext(&directory_object, &file_object); } // if (0 != file_object.fname[0]) // { // strcpy(directory_name, file_object.fname); //directory_name = file_object.fname; // } f_closedir(&directory_object); return 0; }
/** * Initialize the peripherals and state for this task. */ uint8_t camera_task_setup() { /* Initialize I2C peripherals for this task. */ ov5642_init(); lps331_init(); hts221_init(); /* Intialize SPI peripherals for this task. */ spi_take(); arduCamInstalled = arducam_init(); /* Try to mount the SD card. */ if (fn_initvolume(mmc_spi_initfunc) != F_NO_ERROR) { trace_printf("sdcard: failed to mount volume\n"); spi_give(); return 0; } #ifdef CLEAN_SD_CARD /* Delete DATA.LOG and JPG files from the SD card. */ trace_printf("camera_task: cleaning SD card\n"); f_delete("DATA.LOG"); f_delete("file.txt"); F_FIND xFindStruct; if (f_findfirst("*.JPG", &xFindStruct) == F_NO_ERROR) { do { f_delete(xFindStruct.filename); } while (f_findnext(&xFindStruct) == F_NO_ERROR); } #endif spi_give(); return 1; // OK }
static u32 loadPayload(const char *pattern) { char path[30] = "/luma/payloads"; DIR dir; FILINFO info; FRESULT result = f_findfirst(&dir, &info, path, pattern); f_closedir(&dir); if(result != FR_OK || !info.fname[0]) return 0; path[14] = '/'; u32 i; for(i = 0; info.fname[i]; i++) path[15 + i] = info.fname[i]; path[15 + i] = '\0'; FIL payload; unsigned int br; f_open(&payload, path, FA_READ); f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br); f_close(&payload); return 1; }
size_t enumerateDir(char ***output, char *path, char *pattern) { DIR dp; FILINFO fno; FRESULT fr; char **out = NULL; size_t pathlen = strlen(path); if (pathlen >= FF_LFN_BUF) goto end; fr = f_findfirst(&dp, &fno, path, pattern); char pathb[FF_LFN_BUF] = {0}; strcpy(pathb, path); pathb[pathlen] = '/'; int i = 0; while (fno.fname[0] != 0 && fr == FR_OK) { if (fno.fname[0] == '.') goto next; out = (char **)realloc(out, (i+1) * sizeof(char *)); out[i] = (char *)malloc(FF_LFN_BUF); strcpy(out[i], pathb); strcat(out[i], fno.fname); pathb[pathlen+1] = 0; i++; next: f_findnext(&dp, &fno); } end: f_closedir(&dp); *output = out; return i; }
directory_iterator::directory_iterator( const std::filesystem::path::value_type* path, const std::filesystem::path::value_type* wild ) { impl = std::make_shared<Impl>(); const auto result = f_findfirst(&impl->dir, &impl->filinfo, reinterpret_cast<const TCHAR*>(path), reinterpret_cast<const TCHAR*>(wild)); if( result != FR_OK ) { impl.reset(); // TODO: Throw exception if/when I enable exceptions... } }
u32 defPayloadExists(void) { DIR dir; FILINFO info; FRESULT result = f_findfirst(&dir, &info, "/luma/payloads", "def_*.bin"); f_closedir(&dir); return (result == FR_OK && info.fname[0]); }
/** * Find the next image name for a JPG capture. */ uint16_t next_image_name(char* buffer, uint8_t length) { F_FIND xFindStruct; for (int i = dcimIndex; i < (dcimIndex + 100); ++i) { snprintf(buffer, length, "dcim%d.jpg", i); if (f_findfirst(buffer, &xFindStruct) == F_ERR_NOTFOUND) { dcimIndex = i + 1; return i; } } return 0; }
void findDumpFile(const char *folderPath, char *fileName) { DIR dir; FRESULT result; for(u32 n = 0; n <= 99999999; n++) { FILINFO info; sprintf(fileName, "crash_dump_%08u.dmp", n); result = f_findfirst(&dir, &info, folderPath, fileName); if(result != FR_OK || !info.fname[0]) break; } if(result == FR_OK) f_closedir(&dir); }
size_t FileMaxSize(const wchar_t *path, const wchar_t *pattern) { size_t maxSize = 0; DIR dir; wchar_t lfn[_MAX_LFN + 1]; FILINFO fno; fno.lfname = lfn; fno.lfsize = _MAX_LFN + 1; if (f_findfirst(&dir, &fno, path, pattern) == FR_OK) { do { if (fno.fsize > maxSize) maxSize = fno.fsize; } while (f_findnext(&dir, &fno) == FR_OK && fno.fname[0]); } f_closedir(&dir); return maxSize; }
/*find a vaild .fsn or .txt file*/ int find_one_vaild_file(char *dirPath, char * matchFile, char *dstName) { FRESULT res; DIR dj; FILINFO fno; #if _USE_LFN char lfn[_MAX_LFN + 1]; fno.lfname = lfn; fno.lfsize = _MAX_LFN + 1; #endif res = f_findfirst(&dj, &fno, dirPath, matchFile); if (res == FR_OK && fno.fname[0]) { f_closedir(&dj); strcpy(dstName, fno.fname); return 0; } f_closedir(&dj); return 1; }
/** * @brief List up to 25 file on the root directory with extension .BMP * @param DirName: Directory name * @param Files: Buffer to contain read files * @retval The number of the found files */ uint32_t Storage_GetDirectoryBitmapFiles(const char* DirName, char* Files[]) { FRESULT res; uint32_t index = 0; /* Open filesystem */ if(f_mount(&fs, (TCHAR const*)"",0) != FR_OK) { return 0; } /* Start to search for wave files */ res = f_findfirst(&MyDirectory, &MyFileInfo, DirName, "*.bmp"); /* Repeat while an item is found */ while (MyFileInfo.fname[0]) { if(res == FR_OK) { if(index < MAX_BMP_FILES) { sprintf (Files[index++], "%s", MyFileInfo.fname); } /* Search for next item */ res = f_findnext(&MyDirectory, &MyFileInfo); } else { index = 0; break; } } f_closedir(&MyDirectory); return index; }
uint32_t tmdPreloadRecent(tmd_data *data, wchar_t *path) { //returns tmd file name contentid DIR dir; FILINFO fno; fno.lfname = NULL; wchar_t *filename; tmd_data data_tmp; uint32_t contentid = 0xFFFFFFFF; if (f_findfirst(&dir, &fno, path, L"*.tmd") == FR_OK) { filename = path + wcslen(wcscat(path, L"/")); do { wcscat(filename, fno.fname); if (tmdPreloadHeader(&data_tmp, path) && (contentid == 0xFFFFFFFF || __builtin_bswap16(data_tmp.header.title_version) > __builtin_bswap16(data->header.title_version)) ) { *data = data_tmp; contentid = wcstoul(filename, NULL, 16); } } while (f_findnext(&dir, &fno) == FR_OK && *fno.fname); } f_closedir(&dir); return contentid; }
static portBASE_TYPE prvDIRCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ) { static F_FIND *pxFindStruct = NULL; unsigned char ucReturned; portBASE_TYPE xReturn = pdFALSE; /* This assumes pcWriteBuffer is long enough. */ ( void ) pcCommandString; /* Ensure the buffer leaves space for the \r\n. */ configASSERT( xWriteBufferLen > ( strlen( cliNEW_LINE ) * 2 ) ); xWriteBufferLen -= strlen( cliNEW_LINE ); if( pxFindStruct == NULL ) { /* This is the first time this function has been executed since the Dir command was run. Create the find structure. */ pxFindStruct = ( F_FIND * ) pvPortMalloc( sizeof( F_FIND ) ); if( pxFindStruct != NULL ) { ucReturned = f_findfirst( "*.*", pxFindStruct ); if( ucReturned == F_NO_ERROR ) { prvCreateFileInfoString( pcWriteBuffer, pxFindStruct ); xReturn = pdPASS; } else { snprintf( pcWriteBuffer, xWriteBufferLen, "Error: f_findfirst() failed." ); } } else { snprintf( pcWriteBuffer, xWriteBufferLen, "Failed to allocate RAM (using heap_4.c will prevent fragmentation)." ); } } else { /* The find struct has already been created. Find the next file in the directory. */ ucReturned = f_findnext( pxFindStruct ); if( ucReturned == F_NO_ERROR ) { prvCreateFileInfoString( pcWriteBuffer, pxFindStruct ); xReturn = pdPASS; } else { /* There are no more files. Free the find structure. */ vPortFree( pxFindStruct ); pxFindStruct = NULL; /* No string to return. */ pcWriteBuffer[ 0 ] = 0x00; } } strcat( pcWriteBuffer, cliNEW_LINE ); return xReturn; }