thanks for you that but what your code is doing is exactly what I need it to do is create a list of files and then upload those files that end with .csv to a server
I have made the changes that you recommended but still get nothing it does not create the file.
/*
* This sketch will list all files in the root directory and
* then do a recursive list of all directories on the SD card.
*
*/
#include <SdFat.h>
#include <SdFatUtil.h>
Sd2Card card;
SdVolume volume;
SdFile root;
SdFat sd;
// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
void error_P(const char* str) {
PgmPrint("error: ");
SerialPrintln_P(str);
if (card.errorCode()) {
PgmPrint("SD error: ");
Serial.print(card.errorCode(), HEX);
Serial.print(',');
Serial.println(card.errorData(), HEX);
}
while(1);
}
void setup() {
Serial.begin(9600);
PgmPrintln("Type any character to start");
// Serial.print("SS_PIN "); Serial.println(SS_PIN, DEC);
while (!Serial.available());
PgmPrint("Free RAM: ");
Serial.println(FreeRam());
// initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
// if (!card.init(SPI_HALF_SPEED))
pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(10, HIGH); // but turn off the W5100 chip!
if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");
// initialize a FAT volume
if (!volume.init(&card)) error("vol.init failed!");
PgmPrint("Volume is FAT");
Serial.println(volume.fatType(),DEC);
Serial.println();
if (!root.openRoot(&volume)) error("openRoot failed");
// list file in root with date and size
PgmPrintln("Files found in root:");
root.ls(LS_DATE | LS_SIZE);
Serial.println();
// Recursive list of all directories
PgmPrintln("Files found in all dirs:");
root.ls(LS_R);
Serial.println();
PgmPrintln("Done");
PgmPrintln("start of CSV List __________________>");
createPlaylistFile();
}
uint16_t createPlaylistFile(void)
// create a playlist file on the SD card with the names of the files.
// This will then be used in the menu.
{
SdFile plFile; // Playlist file
SdFile lFile; //list files
uint16_t count; // count of files
int FNAME_SIZE;
char fname[128];
char file_list[200] = "FILELIST.TXT" ;
char *CSV_EXT = ".csv";
// open/create the playlist file
!plFile.open(file_list, O_CREAT|O_WRITE);
//LCDErrMessage("PL create fail", true);
count = 0;
while (lFile.openNext(sd.vwd(), O_READ))
{
if (lFile.isFile())
{
lFile.getFilename(fname);
if (strcmp(CSV_EXT, &fname[strlen(fname)-strlen(CSV_EXT)]) == 0)
// only include files with MIDI extenstion
{
plFile.write(fname, 100 );
count++;
}
}
lFile.close();
}
// close the playlist file
plFile.close();
return(count);
}
void loop() {
}