List only *.csv files

with the bizarre indenting

it was from the original code from marco that I have changed to get working with what I need, I have cleaned up the code a bit more.

and I have tried to change the way it logs to a file separately they both work but together they don't instead of writing the list of files to a file can I write it to a buffer?

#include <SdFat.h>
#include <SdFile.h>

// SD chip select pin
const uint8_t chipSelect = SS;

// file system object
SdFat sd;
SdFile file;
//SdFile	lFile;		//list files
uint16_t count;		// count of files
int FNAME_SIZE;
char fname[12];
char file_list[] = "FILELIST.TXT";
char *CSV_EXT = "CSV"; 
#define SD_SELECT 4

// define a serial output stream
ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
void setup() {
  Serial.begin(9600);
           
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
 
 
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

Serial.println("program started");

ofstream sdlog(file_list ,  ios::out | ios::app);

 

 count = 0;
 while (file.openNext(sd.vwd(), O_READ))
	{
  Serial.println("Started");
    	if (file.isFile())
		{ file.getFilename(fname);
		if (strcmp(CSV_EXT, &fname[strlen(fname)-strlen(CSV_EXT)]) == 0){
                Serial.print(fname);			
  	         sdlog << (fname,12) << endl;
				count++;
			}
		}
		file.close();
	
}
Serial.println("count");
Serial.print(count); 







 if (!sdlog) sd.errorHalt("append failed");


sdlog.close();
}
 


void loop() {}