• MPLAB Harmony
  • [Solved]Read : Long file name and Short file names simultaneously
2019/04/04 20:43:51
TS9
Dear All,
 
I am trying to read filenames from root '/' directory from USB MSD. Succeeded .. But Below Code only worked for either fname or lfname individually with Harmony V2_04 Generated , PIC32MZEF MCU .
How to read both long file name and short file names simultaneously from Directory .?
Is there any better way to ?
 
 
 

 
 
 
SYS_FS_HANDLE dirHandle;
SYS_FS_FSTAT stat;
char longFileName[300];
uintptr_t  longFileSize;
int NumberOfBmpFiles=0 , ReachEndOfCount =0;
char myBuff[6];
char USBFilesNames[20][20]  ;
 
 
 
 
 
 
 
    PrintString("Read File Name for Directory \r\n") ;           
            dirHandle = SYS_FS_DirOpen("/mnt/myDrive1");

            if(dirHandle != SYS_FS_HANDLE_INVALID)
            {
                  PrintString(" Directory read Successful \r\n");  
                // Directory open is successful
            }
            // If long file name is used, the following elements of the "stat"
            // structure needs to be initialized with address of proper buffer.
            stat.lfname = longFileName;
            stat.lfsize = 300;
            while(ReachEndOfCount == 0)
            {
                if(SYS_FS_DirSearch(dirHandle, "*.BMP", SYS_FS_ATTR_ARC, &stat) == SYS_FS_RES_FAILURE)
                {
                     // Specified file not found
                
                    PrintString(" Specified file not found \r\n") ;  
                }
                else
                {                    
                    // Directory read succeeded.
                    if ((stat.lfname[0] == '0') && (stat.fname[0] == '0'))
                    {
 
                            ReachEndOfCount  = 1 ;  // Break While
                          // reached the end of the directory.                      
                        break;
                    }
                    else
                    {
                        // continue reading the directory.
                        // File found. Read the complete file name from "stat.lfname" and
                        // other file parameters from the "stat" structure
                        // Specified file not found
                        printf(" File Name = %d  ",NumberOfBmpFiles);                      
                        strcpy(USBFilesNames[NumberOfBmpFiles],stat.fname);
                        printf(USBFilesNames[NumberOfBmpFiles]) ;                    
                        NumberOfBmpFiles++;                 
                        printf("  \r\n") ;                     
                    }                  
                }
            }
 
 
 
 
 
 
 

 
Thanks in Advance..
 
--
TS9
2019/04/05 10:49:00
TS9
Any update?
2019/04/05 10:49:01
TS9
Any update?
2019/04/30 09:25:26
TS9
Please check highlighted in Bold in code for solution  .

SYS_FS_HANDLE dirHandle;
SYS_FS_FSTAT stat;
char longFileName[300],*fn;
uintptr_t  longFileSize;
int NumberOfBmpFiles=0 , ReachEndOfCount =0;
char myBuff[6];
char USBFilesNames[20][20]  ;
 
    PrintString("Read File Name for Directory \r\n") ;           
            dirHandle = SYS_FS_DirOpen("/mnt/myDrive1");

            if(dirHandle != SYS_FS_HANDLE_INVALID)
            {
                  PrintString(" Directory read Successful \r\n");  
                // Directory open is successful
            }
            // If long file name is used, the following elements of the "stat"
            // structure needs to be initialized with address of proper buffer.
            stat.lfname = longFileName;
            stat.lfsize = 300;
            while(ReachEndOfCount == 0)
            {
                if(SYS_FS_DirSearch(dirHandle, "*.BMP", SYS_FS_ATTR_ARC, &stat) == SYS_FS_RES_FAILURE)
                {
                     // Specified file not found
                
                    PrintString(" Specified file not found \r\n") ;  
                }
                else
                {                    
                    // Directory read succeeded.
                    if ((stat.lfname[0] == '0') && (stat.fname[0] == '0'))
                    {
 
                            ReachEndOfCount  = 1 ;  // Break While
                          // reached the end of the directory.                      
                        break;
                    }
                    else
                    {
 
                           fn = *stat.lfname ? stat.lfname : stat.fname;                     // continue reading the directory.
                        // File found. Read the complete file name from "stat.lfname" and
                        // other file parameters from the "stat" structure
                        // Specified file not found
                        printf(" File Name = %d  ",NumberOfBmpFiles);                      
                        strcpy(USBFilesNames[NumberOfBmpFiles],fn);
                        printf(USBFilesNames[NumberOfBmpFiles]) ;                    
                        NumberOfBmpFiles++;                 
                        printf("  \r\n") ;                     
                    }                  
                }
            }
 
 

2019/04/30 13:43:01
qhb
TS9
Please check highlighted in Bold in code for solution  .

Bolding does not work inside code blocks. Removing them does make it visible.
 

SYS_FS_HANDLE dirHandle;
SYS_FS_FSTAT stat;
char longFileName[300],*fn;
uintptr_t  longFileSize;
int NumberOfBmpFiles=0 , ReachEndOfCount =0;
char myBuff[6];
char USBFilesNames[20][20]  ;
 
    PrintString("Read File Name for Directory \r\n") ;           
            dirHandle = SYS_FS_DirOpen("/mnt/myDrive1");

            if(dirHandle != SYS_FS_HANDLE_INVALID)
            {
                  PrintString(" Directory read Successful \r\n");  
                // Directory open is successful
            }
            // If long file name is used, the following elements of the "stat"
            // structure needs to be initialized with address of proper buffer.
            stat.lfname = longFileName;
            stat.lfsize = 300;
            while(ReachEndOfCount == 0)
            {
                if(SYS_FS_DirSearch(dirHandle, "*.BMP", SYS_FS_ATTR_ARC, &stat) == SYS_FS_RES_FAILURE)
                {
                     // Specified file not found
                
                    PrintString(" Specified file not found \r\n") ;  
                }
                else
                {                    
                    // Directory read succeeded.
                    if ((stat.lfname[0] == '0') && (stat.fname[0] == '0'))
                    {
 
                            ReachEndOfCount  = 1 ;  // Break While
                          // reached the end of the directory.                      
                        break;
                    }
                    else
                    {
 
 
 
                           fn = *stat.lfname ? stat.lfname : stat.fname;                     // continue reading the directory.
                        // File found. Read the complete file name from "stat.lfname" and
                        // other file parameters from the "stat" structure
                        // Specified file not found
                        printf(" File Name = %d  ",NumberOfBmpFiles);                      
                        strcpy(USBFilesNames[NumberOfBmpFiles],fn);
                        printf(USBFilesNames[NumberOfBmpFiles]) ;                    
                        NumberOfBmpFiles++;                 
                        printf("  \r\n") ;                     
                    }                  
                }
            }
 



2019/05/01 04:24:42
Chris A
qhb
Bolding does not work inside code blocks. Removing them does make it visible.

Umm.  oddly it did work for me and on the 3 browsers I just tried ( OS x Safar1 & firefox, w1n Edge )...
© 2019 APG vNext Commercial Version 4.5

Use My Existing Forum Account