unfortunately some of the primitive functions are not directly available with the
SdFat sd;
object. Hence precluding the use of the "ls" function. The following code should accomplish what you want. It passes the sd objects current file to the pointer a directory entry object of pointer p. which then can have its attributes tested to see if they are hidden or other.
Note there is a method to test if a directory entry is long name. However, I do not believe the entry is caching the long name itself.
The below does compile. And 99.5 of it is from working code that I use. I have added the attribute and long file name detection, so it should work.
void ListFiles2(uint8_t flags) {
// This code is just copied from SdFile.cpp in the SDFat library
// and tweaked to print to the serial output in html!
dir_t p;
sd.vwd()->rewind();
Serial.println();
while (sd.vwd()->readDir(&p) > 0) {
// done if past last used entry
if (p.name[0] == DIR_NAME_FREE) break;
// skip deleted entry and entries for . and ..
if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;
// only list subdirectories and files
if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
if ((p.attributes & DIR_ATT_HIDDEN) != DIR_ATT_HIDDEN) continue;
// print any indent spaces
Serial.print(F(" "));
for (uint8_t i = 0; i < 11; i++) {
if (p.name[i] == ' ') continue;
if (i == 8) {
Serial.print('.');
}
Serial.print((char)p.name[i]);
}
Serial.print(F(" "));
// print file name with possible blank fill
for (uint8_t i = 0; i < 11; i++) {
if (p.name[i] == ' ') continue;
if (i == 8) {
Serial.print('.');
}
Serial.print((char)p.name[i]);
if (DIR_IS_LONG_NAME(&p)) {
Serial.print(F(" long fn"));
}
}
if (DIR_IS_SUBDIR(&p)) {
Serial.print('/');
}
// print modify date/time if requested
if (flags & LS_DATE) {
sd.vwd()->printFatDate(p.lastWriteDate);
Serial.print(' ');
sd.vwd()->printFatTime(p.lastWriteTime);
}
// print size if requested
if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
Serial.print(' ');
Serial.print(p.fileSize);
}
Serial.println();
}
Serial.println();
}