1

I'm using the SDFat library and the FatFile type has the functions:

bool FatFile::dirEntry(dir_t* dir)

Return a file's directory entry.

Parameters

[out] dir Location for return of the file's directory entry.

Returns

The value true is returned for success and the value false is returned for failure.

And

uint8_t FatFile::dirName(const dir_t *dir, char *name)

Format the name field of dir into the 13 byte array name in standard 8.3 short name format.

Parameters

[in] dir The directory structure containing the name.

[out] name A 13 byte char array for the formatted name.

Returns

length of the name.

From what I understand, I should be able to pass something like this into the functions:

dir_t Bass;
char dName [13];
FatFile BrowseFile;
BrowseFile.open("/Folder1/File1.txt", O_RDONLY);
Serial.print(BrowseFile.dirEntry(&*Bass));
Serial.print(BrowseFile.dirName(Bass,*dName));
Serial.println(dName);

to which the program should output

1
[Folder1's 8.3 name length]
[Folder1's 8.3 name]

However, I'm getting an error and I can't find any included examples that use these two functions in a sketch. if someone could explain what I'm doing wrong, it would be greatly appreciated.

  • 2
    However, I'm getting an error Then post the full error. – per1234 Jul 15 '17 at 10:14
2

dir_t * is a pointer to a variable of type dir_t.

I don't know the API to which you refer, but the format for passing it would be:

dir_t Bass;
char dName[13];
BrowseFile.dirEntry(&Bass);
BrowseFile.dirName(&Bass, dName);
Serial.println(dName);
  • Thank you, that seems to be the correct format. Unfortunately, it returns information on File1.txt and not Folder1 which makes it less useful. Also, a link to the API is now in the question – ATE-ENGE Jul 14 '17 at 21:08
  • 1
    Well, .dirEntry() gets the entry in the directory for the file, not the directory the file is in. FAT has no way of going "up" from a file. In fact I am not aware of any filesystem that has the concept of "up" - even going up a directory in a tree is actually going down into the directory called ".." – Majenko Jul 14 '17 at 21:10
  • Oh, then I have a misunderstanding in regards to how FAT files work. Is there a good resource I can use to learn more about FAT? How would I go up a directory in a tree? Would it be as easy as saying BrowseFile.open([&directory],"..",O_READ? – ATE-ENGE Jul 14 '17 at 21:14
  • 1
    In most filesystems a directory contains two special files ".", which is the current directory, and ".." which is the parent directory. If you want to go up the tree you have to get the ".." directory entry and open that as a directory. There's nothing like that for a file though, only directories. You can start here for FAT information: en.wikipedia.org/wiki/File_Allocation_Table – Majenko Jul 14 '17 at 21:17
2

what is dir_t*?

a pointer to a data type called dir_t -> it must have been defined somewhere in your code/libraries used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.