Home > Mobile >  Why changing directory using elm chan fatfs f_chdir doesnt effect directory structure?
Why changing directory using elm chan fatfs f_chdir doesnt effect directory structure?

Time:12-31

My folder structure is like this : I open a folder then I use f_chdir to change my directory to that folder. The problem is that f_chdir doesn't change my Directory Structure variable.

-A1
   | A11 
   |     |
   |     A11.mp3
   | A12
   |     |
   |       A12.mp3
   | A1.mp3

-A2
   | A21 
   |     |
   |     A21.mp3
   | A22
   |     |
   |       A22.mp3
   | A2.mp3
root_path = "/A1";
newPath = "/A1/A11";
f_opendir(dir,root_path );
f_chdir(newPath);
f_readdir(dir,fno);// This results in fno.fname = "/A12"

How can I change:

f_readdir(dir,fno);// This results in fno.fname = "/A12" 

to this behavior?:

f_readdir(dir,fno);// Resulting in fno.fname = "A11.mp3"

CodePudding user response:

f_readdir only works with the directory that has been opened. f_chdir does not affect your dir variable in any way. If you want to update dir, then re-open the needed directory:

f_closedir(dir);
f_opendir(dir, newPath);
f_readdir(dir, fno);

or using the dot directory:

f_closedir(dir);
f_chdir(newPath);
f_opendir(dir, ".");
f_readdir(dir, fno);
  • Related