| // this little helper is used to traverse paths | // this little helper is used to traverse paths | ||||
| SdFile SDClass::getParentDir(const char *filepath, int *index) { | SdFile SDClass::getParentDir(const char *filepath, int *index) { | ||||
| // get parent directory | // get parent directory | ||||
| SdFile d1 = root; // start with the mostparent, root! | |||||
| SdFile d1; | |||||
| SdFile d2; | SdFile d2; | ||||
| d1.openRoot(volume); // start with the mostparent, root! | |||||
| // we'll use the pointers to swap between the two objects | // we'll use the pointers to swap between the two objects | ||||
| SdFile *parent = &d1; | SdFile *parent = &d1; | ||||
| SdFile *subdir = &d2; | SdFile *subdir = &d2; | ||||
| if (!parentdir.isOpen()) | if (!parentdir.isOpen()) | ||||
| return File(); | return File(); | ||||
| // there is a special case for the Root directory since its a static dir | |||||
| if (parentdir.isRoot()) { | |||||
| if ( ! file.open(SD.root, filepath, mode)) { | |||||
| // failed to open the file :( | |||||
| return File(); | |||||
| } | |||||
| // dont close the root! | |||||
| } else { | |||||
| if ( ! file.open(parentdir, filepath, mode)) { | |||||
| return File(); | |||||
| } | |||||
| // close the parent | |||||
| parentdir.close(); | |||||
| if ( ! file.open(parentdir, filepath, mode)) { | |||||
| return File(); | |||||
| } | } | ||||
| // close the parent | |||||
| parentdir.close(); | |||||
| if (mode & (O_APPEND | O_WRITE)) | if (mode & (O_APPEND | O_WRITE)) | ||||
| file.seekSet(file.fileSize()); | file.seekSet(file.fileSize()); |