I added a close function to the while loop.
//// Count the amount of Files in the LogFiles Directory ////
countFile = SD.open("LogFiles/");
while (true) {
File entry = countFile.openNextFile();
if (! entry) {
break;
}
entry.close();
fileCount++;
}
fileCount++; //Add one to fileCount to creat the next file
//// Create a new file ////
String FileName = String("LogFiles/Log0") + fileCount + String(".csv");
logFile = SD.open(FileName, FILE_WRITE);
logFile.println("Header1, Header2, Header3, Header4, Header5, Header6, Header7, Header8");
This code does work and creates files with headers every time I turn the Arudino on. But now I am having the issue when there are more than two files it takes an incredibly long time to create another file and write the header. About 10 seconds.