How to search directory and find folder's name in Azure filex

Ali Shahvaran 20 Reputation points
2023-02-24T12:07:14.98+00:00

Hello every one

I am new to Azure RTOS, and now I want to search and find folders in USB or SDCARD but I could not find any function to do this. Is there any solution?

(working on STM32F)

something like this:

FRESULT scan_files (
    char* path        /* Start node to be scanned (***also used as work area***) */
)


  res = f_opendir(&dir, path);                       /* Open the directory */
    if (res == FR_OK) {
        for (;;) {
            res = f_readdir(&dir, &fno);                   /* Read a directory item */
						//sprintf(getfname, "%s", fno.fname);
					//len=strlen(getfname);
					//sprintf(getfname2[x], "%c",getfname[0]);
				
            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
            if (fno.fattrib & AM_DIR) {                    /* It is a directory */
                i = strlen(path);
              sprintf(path,"/%s", fno.fname);
						
                res = scan_files(path);                    /* Enter the directory */
                if (res != FR_OK) break;
                path[i] = 0;
            } else {                                       /* It is a file. */
Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
331 questions
0 comments No comments
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 14,676 Reputation points Microsoft Employee
    2023-02-24T17:51:18.19+00:00

    Hi @Ali Shahvaran Greetings. Welcome to Microsoft Q&A forum! Thank you for posting this question.

    I would like to check with you and see if you have looked into the GitHub repository on FlieX which provides an header file fx_directory.h which has different methods available to browse the directory. Please leverage this file and build the solution on top of the definitions provided in the file.

    Refer the demo_filex.c sample code provided as a reference on how to use the methods defined. Please let us know if you run into any issues or need any additional assistance.


    • Kindly mark the answer as useful if the response is helpful so that it would benefit other community members facing the same issue. 
    • Original posters help the community find answers faster by identifying the correct answer. Here is how 
    • I highly appreciate your contribution to the community. 
    1 person found this answer helpful.

4 additional answers

Sort by: Most helpful
  1. Scott Azure RTOS 4,051 Reputation points
    2023-02-24T17:37:14.9666667+00:00

  2. Ali Shahvaran 20 Reputation points
    2023-02-25T14:32:37.5466667+00:00

    status = fx_directory_next_entry_find(&my_media, next_name);

    this function works but can't search inside a folder.
    How can set the address for this function or any alternative for that?

    0 comments No comments

  3. Ali Shahvaran 20 Reputation points
    2023-02-26T12:44:13.68+00:00

    Problem solved, this way:

    status = fx_directory_default_set(fx_media,"backgrand");
    	status = fx_directory_next_entry_find(fx_media, next_name);
    

    just there is no way to set the default directory to the main path.
    why?


  4. Ali Shahvaran 20 Reputation points
    2023-03-04T13:28:33.44+00:00

    Finally, I could find the solution this function works perfectly

    thank you so much 'Azure'

    UINT

    fx_directory_local_path_set

    (FX_MEDIA *media_ptr, FX_LOCAL_PATH *local_path_ptr,

    CHAR *new_path_name)

    ;


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.