[sdfat] How can I print differently than to Serial

Hello and happy new year,

I am using sdfat and Iam working around this function

files.printFileSize(&Serial);

This file print in my terminal the size of the file.

I create a print function

sprintln(char *text, int log){}

when int log is
0 => print in terminel
1 => write in sd card (log file)
2 => both

As I want to write the print in my logfile of my Sd card

files.printFileSize(&Serial);

I would like to use my function sprintln() (or sprint())

Tell me if I am wrong,
if files.printFileSize() rint in terminal, is because ther &Serial as parameter.

But now, how can I adapt it to have it in sprintln(,2)?

Would it be possible to do it

sprintln(files.printFileSize(&Serial),2)

;
or

sprintln(files.printFileSize(&Serial),1)

(1 is to only write in log file of my sd card)

Thank for your advises!
Cheers

What class is the files object an instance of?

What does the printFileSize() method actually take as an input argument?

What does the method actually do?

Would it be possible to do it

I'm sure that that would do something. Almost certainly not what you want. The argument to the printFileSize() method is an instance of some class is to handle the data. There is likely nothing returned by the method.

Dear Paul

Thank for your reply.

I found this (in the lib), does it help?

size_t FatFile::printFileSize(print_t* pr) {
  char buf[11];
  char *ptr = buf + sizeof(buf);
  *--ptr = 0;
  ptr = fmtDec(fileSize(), ptr);
  while (ptr > buf) {
    *--ptr = ' ';
  }
  return pr->write(buf);
}

does it help?

Not really, because someone is abusing the _t convention. The _t normally means that the type is standard, but that type clearly is not.

It looks, though, like the function takes a pointer to something that has a print method that knows how to output some data, using the write() method.

That function simply calls fileSize(), inside the call to fmtDec(). I's need to know what those two functions do.

However, since File derives from Stream which derives from Print, where the write() method is defined, it appears that you can pass a File instance to the function, just like you pass a HardwareSerial instance.

Thank Pauls for your help.

I am lost with this problem and I do not know how to answer. I also ovserved I do have another function whih works excepted for write while reading. But I going to open an ther topic.

Thank for helping