Working directory and or path for SdFat?

I just noticed that the Arduino team will be using SdFat to implement an SD library in 0022. They will include paths in their library.

http://arduino.cc/en/Reference/SD

I have been doing a major rewrite of SdFat and decided to implement a current working directory so sub-directories would be easier to use.

I did a prototype path implementation but found a current working directory easier to use. Please look at the sample sketch below and give me your comments.

The new SdFat also has iostream style error handling in addition to the return of a bool true/false.

I plan to implement a SdStream class in the future with extraction and insertion operators and many of the iostream manipulators.

SdFat allows multiple files to be open. Here is a sample sketch using the SdFat class:

#include <SdFat.h>
SdFat sd;
SdFile file;

void setup(void) {
  Serial.begin(9600);

  // initialize SD and file system
  sd.init();

  // create "MY_SUB" if it does not exist
  if (!sd.exists("MY_SUB")) sd.mkdir("MY_SUB");

  // make "MY_SUB" the current working directory
  sd.cd("MY_SUB");

  // open or create "MY_FILE.TXT" in "MY_SUB"
  file.open("MY_FILE.TXT", O_WRITE | O_APPEND | O_CREAT);

  // append a line to "MY_FILE.TXT"
  file.println("Append a line to the file");

  // close "MY_FILE.TXT" so data is written to SD
  file.close();

  // new error state like iostream
  if (file.fail()) {
    Serial.println("failed");
  } else {
    Serial.println("success");
  }
}

void loop(void) {}

If you have multiple files open you probably have multiple CWD’s so how does the Arduino knows the right one?

The concept of paths as proposed by http://arduino.cc/en/Reference/SD forces the programmer to allways type the whole path or use a var (if I understood correctly) and that makes debugging easier. NB the path and the filename are always side by side in the code and with a CWD there can be many lines between them…

But I see value in a single CWD which is read-only to do things like (pseudocode)

sd.open("/a/b/c/d/e/file.txt")
sd.open(cwd+“file2.txt”);

It might save some precious RAM …

my 2 cents
Rob