Renaming files on the SD card

You are not reading or looking at examples.

You must use:

SdFat sd;

Don't use any of this stuff in new versions of SdFat when you use the above.

Sd2Card card;
SdVolume volume;
SdFile root;

Remove this from setup:

  volume.init(&card);             
  root.openRoot(&volume);

You are duplicating RAM use and functionality by putting in both. Things won't be initialized correctly.

Look at the examples in the extras/examplesV1 folder and the SdFat/examples folder.

I did not find any example code on how to generate an http listing using sd.ls() from the new SdFat library.

The ListFiles(Client client, uint8_t flags) function that I'm using is from ladyada (http://www.ladyada.net/learn/arduino/ethfiles.html) and is derived using Sd2Card card; SdVolume volume; SdFile root.

Unless someone wants to volunteer some new example code, I am, for now, going to double-up on the use of card.init(SPI_HALF_SPEED, 4)) and sd.init(SPI_HALF_SPEED, 4))

So far things are working correctly.

ladyada used an older version of SdFat, much older.

I changed SdFat since she wrote that article. I am the author of SdFat so I know how it works.

card.init(), volume.init() and openRoot() are now called in SdFat::init() in your call:

  sd.init(SPI_HALF_SPEED, 4))

init() should not be called for two instances of Sd2card and two instances of SdVolume.

root should not be opened twice.

Doing these things will cause problems.

It is working with both card.init and sd.init… for now.

I am not an expert in C/C++ and for my project timeframe, I do not have time to be. If you know what exactly needs to be altered in the ListFiles() function, please let me know.

From what I’ve gathered, I need to delete volume and root designations and use class SdFat sd. Use the sd class in sd.init to initialise the SD card. However, I do not know what to change root.* in the ListFiles() function to. See below.

#include <SdFat.h>
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

void setup() {

card.init(SPI_HALF_SPEED, 4);
}

void loop() {

ListFiles(client, LS_SIZE);

}

void ListFiles(Client client, uint8_t flags) {
  dir_t p; 
  root.rewind();
  client.println("<ul>");
  while (root.readDir(p) > 0) {
    if (p.name[0] == DIR_NAME_FREE) break;
    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;
    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
    client.print("<li><a href=\"");
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
    client.print("\">");
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if (i == 8) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
    client.print("</a>");
    if (DIR_IS_SUBDIR(&p)) {
      client.print('/');
    }
    if (flags & LS_DATE) {
       root.printFatDate(p.lastWriteDate);
       client.print(' ');
       root.printFatTime(p.lastWriteTime);
    }
    if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
      client.print(' ');
      client.print(p.fileSize);
    }
    client.println("</li>");
  }
  client.println("</ul>");
}

fat16lib: To open or create a file for append in SdFat

  if (datafile.open("logfile.txt", O_WRITE | O_CREAT | O_APPEND)) {
    dataFile.println("Hello");
    dataFile.close();
  }

If you declared

SdFat sd;

use

  if (sd.exists("now.csv"))

Dear Fat16lib sir, that's a great work you have done. Now, I have gone to the doc section in github and it's a bunch of html codes. I cant read it... do you have any other location for docs?? coz I'm in a planning to change my codes to move to sdfat.

Mishu~