SD Fat Find parent folder help

I'm looking to make a function that uses the SDFat library to browse for the next file in an SD card. When it finds a folder, it opens the folder and reads the contents in lexicographic order and then, after it finishes with the folder, it should reopen that folder's parent directory and continue on.
(equivalent to [FatFile].ls(&Serial, LS_R); except stopping at each file)

Right now my function looks like this:

Init Steps

*Pass in Disp to get file name out for an LCD

*Pass in movement as I may want to go n files forward in the future

*Then Open the next file in global var SDFat dirFile (the SD card's current active folder)

    char SDBrowse (char *Disp, int movement)
    {
      char SFN[13];        //shrot file name allocation space to check for .CSV extension
      FatFile BrowseFile;  //Allocation to get next FatFile 
      while(movement>0)
      {
        if(!BrowseFile.openNext(&dirFile, O_RDONLY)) 
        {

(if openNext==false, BrowseFile may be either a subdirectory or at the end of a folder) ->Test to determine accordingly:

if BrowseFile is a SubDirectory, set dirFile to BrowseFile and read the 1st file

          if(BrowseFile.isSubDir())
          {
            BrowseFile.open(&dirFile,BrowseFile.dirIndex(), O_READ);
            dirFile=BrowseFile;
            BrowseFile.close();
            BrowseFile.openNext(&dirFile, O_READ);
            Serial.print("sub ->");      //debug
            dirFile.printName(&Serial);  //debug
            Serial.println();            //debug
          }

Here's where I'm having toubble
this element of the function is supposed to determine the parent folder of dirFile, open its parent, set dirFile=[parent], and open BrowseFile at dirFile's index in the parent folder +1. However, it seems to be just closing and reopening dirFile.

          else if(dirFile.isSubDir())
          {
            
            uint16_t dirpos=dirFile.dirIndex();
            SdFile *ParentDir;
            BrowseFile.close();
            //open Parent
            ParentDir=dirFile.cwd();
            //ParentDir.open(dirFile.cwd(),"/",O_READ);
            //move dirFile up
            dirFile.close();
            dirFile.setCwd(ParentDir);
            //ParentDir.close();
            //reopen Browse at dir+1
            BrowseFile.open(&dirFile,dirpos+1, O_READ);
            Serial.print("up ->");          //debug
            dirFile.printName(&Serial);     //debug
            Serial.println(" New Parent");  //debug
          }

If BrowseFile.openNext(&dirFile, O_RDONLY)==false andneither BrowseFile nor dirFile are sub directories, it follows that BrowseFile has reached the end of the root directory. The function closes BrowseFile and dirFile and reopens dirFile at the root to restart from the top.

          else
          {
            BrowseFile.close();
            dirFile.close();
            dirFile.open("/",O_READ);
            Serial.println("reset");  //debug
          }
        } //end of if(!BrowseFile.openNext(&dirFile, O_RDONLY)) statement

If BrowseFile.openNext(&dirFile, O_RDONLY)==true, double check to make sure its a file and not hidden. Then, if there's a .csv extension, decrement movement and if movement--=0 feed it to Disp.....

       else if(BrowseFile.isFile()&& !BrowseFile.isHidden())
        {
          BrowseFile.getSFN(&*SFN);         
          if(strstr(SFN,".CSV") != NULL)
          {
            BrowseFile.printName(&Serial);  //debug
            Serial.println();               //debug
            movement--;
            if(movement=0){BrowseFile.getName(Disp,17);}
          }
        }
      }
    }

I'm relatively new to working with computer file structures at this level, so there may be something I'm missing. Please let me know if there something I'm missing or if there's anything I can do better within the code itself.

In post #4 of this thread in french I attached code that goes recursively through the files hierarchy

That could give you some ideas (some comments are in French but code is code)

Printing all the files sorted alphabetically at a given level will require a buffer and sort which will eat up memory

J-M-L:
In post #4 of this thread in french I attached code that goes recursively through the files hierarchy

That could give you some ideas (some comments are in French but code is code)

Printing all the files sorted alphabetically at a given level will require a buffer and sort which will eat up memory

This does help, ( I think I can make some optimizations on what I see here) I can use this function to get the parent directory by searching the entire SD card from the top. However, I feel like there has to be a better way.

The code was a quick hack to see the traversal of the hierarchy

To go to the parent dir is not handled I think - there was an old thread about this