Create filescatalog on targetSD

Hi all!

I have been struggling with a program to create a catalog of files from an SD and write it to that SD, using the printDirectory function from Listfiles (https://www.arduino.cc/en/Tutorial/listfiles).
My objective is to create a catalog which contains the full filenames, including directories and subdirectories, from all files in an SD and write that catalog to the SD at the same time.
Here is the code I produced (derived from Listfiles):

void makeCatalog(File dir) {
catalog.print(dir.name());
Serial.print(dir.name());
while (true) {
File entry = dir.openNextFile();
if (!entry) {
Serial.print(“No more files”);
break;
}
if (entry.isDirectory()) {
catalog.print("/ “);
Serial.print(”/");
makeCatalog(entry);
} else {
catalog.print(entry.name());
Serial.print(entry.name());
catalog.print(" | size: “);
Serial.print(” | size: ");
unsigned long fsize(entry.size());
char temp[16];
ltoa(fsize,temp,10);
catalog.println(temp);
Serial.println(temp);
}
entry.close();
}
catalog.println();
Serial.println();
}

The catalog-file is already created and open on functioncall.
When I comment out the writes to the catalog, I do get output on the serial monitor (not exactly how I want it, but that should be solved by printing to the file).
But as soon as I enable the catalog-writes, the only thing I get is on the monitor: ‘’ and then ‘Done!’ (which is printed as the function returns to the main program. (root is the startingpoint, where also the catalog-file -catalog.txt- will be written).
I was wondering if the fact that the catalog-file is opened in root while I am building the catalog from the root is the cause of this disfunctioning. Or maybe I overlooked something else obvious?
Does anyone have a suggestion or clue?
Thanks in advance for your thoughts!

Kind regards,
Fred.