436 views
in System Integration by

Hello, 

I am developing an application which scaning files from an usb using chan's filesystem libraries. I want to read all directories recursively and store file names in an array.

It works good but any idea that how can i get files names in an array ?

array string temp_array[50];
var int32 result = 0;
var int32 file_count = 0;
native(temp_array,result,file_count)
{
    FRESULT res;
    DIR dir;
    UINT i;
    static FILINFO fno;

    static int count = 0;

    char scan_file_path[1024];

    sprintf(scan_file_path,"%s",(char *)path);

    res = f_opendir(&dir, scan_file_path);                /* Open the directory */
    result = res;
    if (result == FR_OK)
    {
    	for (;;)
    	{
    		result = f_readdir(&dir, &fno);                   /* Read a directory item */
    		if (result != 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(scan_file_path);
    			sprintf(&scan_file_path[i], "/%s", fno.fname);
    			result = FileBrowserFileBrowserWidget_scan_files(_this,scan_file_path);/* Enter the directory */
    			if (result != FR_OK) break;
    			scan_file_path[i] = 0;
    		}
    		else
    		{  /* It is a file. */ // THIS IS THE PART THAT I WANT TO STORE
    			temp_array[count] = EwNewStringUtf8(fno.fname,1024);
          count = count + 1;
    		}
    	}
    	f_closedir(&dir);
    }
    file_count = count;
    
}


return result;

 

1 Answer

0 votes
by
Hello,

it is not possible to pass an array to native code. Chora is a save and stable programming language that does not allow the exchange of data pointers. Since the size of a Chora-array is unknown in the native C-code, this interaction would cover a high risk for programming errors. Therefore Embedded Wizard does not offer any data exchange by addresses or pointers like for an array.

In your case, you can make the entire filesystem access in the C world and store the entire list of files in your C database. The API to access your filesystem can then provide functions to query the number of files and to return the name of a certain file number. By such an interface it will be easy to show all file names within a vertical list.

Does this help?

Best regards,

Manfred.

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...