• AVR Freaks

Hot![Solved]Read : Long file name and Short file names simultaneously

Author
TS9
Super Member
  • Total Posts : 649
  • Reward points : 0
  • Joined: 2010/05/07 10:52:22
  • Status: offline
2019/04/04 20:43:51 (permalink)
0

[Solved]Read : Long file name and Short file names simultaneously

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
post edited by TS9 - 2019/04/30 09:21:53
#1

5 Replies Related Threads

    TS9
    Super Member
    • Total Posts : 649
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: Read : Long file name and Short file names simultaneously 2019/04/05 10:49:00 (permalink)
    0
    Any update?
    #2
    TS9
    Super Member
    • Total Posts : 649
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: Read : Long file name and Short file names simultaneously 2019/04/05 10:49:01 (permalink)
    0
    Any update?
    #3
    TS9
    Super Member
    • Total Posts : 649
    • Reward points : 0
    • Joined: 2010/05/07 10:52:22
    • Status: offline
    Re: Read : Long file name and Short file names simultaneously 2019/04/30 09:25:26 (permalink)
    0
    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") ;                     
                        }                  
                    }
                }
     
     

    post edited by TS9 - 2019/04/30 09:32:02
    #4
    qhb
    Superb Member
    • Total Posts : 9917
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: Read : Long file name and Short file names simultaneously 2019/04/30 13:43:01 (permalink)
    0
    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") ;                     
                        }                  
                    }
                }
     



    #5
    Chris A
    Super Member
    • Total Posts : 823
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: Read : Long file name and Short file names simultaneously 2019/05/01 04:24:42 (permalink)
    0
    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 )...
    post edited by Chris A - 2019/05/01 04:25:48
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5