I have question regarding using variable as file name in f_open function.
f_readdir (&mydir, &sdfileinfo)
Once f_readdir
is run in debug mode, I can see my file name in fname
, but I am not sure how to use file name stored in fname
in f_open
function.
I tried to run sdfileinfo.fname
as second argument in f_open
but FR_NOFILE results.
Please see the code below
f_mount(&SDFatFS, "0:", 1) ;
f_opendir (&mydir, "0:/test") ;
f_readdir (&mydir, &sdfileinfo) ;
f_open(&SDFile,sdfileinfo.fname , FA_READ |FA_OPEN_EXISTING ) ;
Edit1:
Please note t123.txt is file under directory test. When I run
f_open(&SDFile, "0:/test/t123.txt", FA_READ)
it runs successfully
Neither
f_opendir
orf_readdir
change the current working directory, which will be0:/
by default. So you are attempting to open0:/t123.txt
rather than0:/test/t123.txt
.You need to include the path in the filename or set the cwd.
Using CWD:
Or construct the full path (less safe and less efficient):