SdFat
Public Member Functions | Static Public Member Functions | Friends | List of all members
FatFile Class Reference

Basic file class. More...

#include <FatFile.h>

Inheritance diagram for FatFile:
Inheritance graph
[legend]

Public Member Functions

int available ()
 
uint32_t available32 ()
 
void clearError ()
 
void clearWriteError ()
 
bool close ()
 
bool contiguousRange (uint32_t *bgnSector, uint32_t *endSector)
 
bool createContiguous (const char *path, uint32_t size)
 
bool createContiguous (FatFile *dirFile, const char *path, uint32_t size)
 
uint32_t curCluster () const
 
uint32_t curPosition () const
 
bool dirEntry (DirFat_t *dir)
 
uint16_t dirIndex ()
 
uint32_t dirSize ()
 
void dmpFile (print_t *pr, uint32_t pos, size_t n)
 
bool exists (const char *path)
 
 FatFile ()
 
 FatFile (const char *path, oflag_t oflag)
 
void fgetpos (fspos_t *pos)
 
int fgets (char *str, int num, char *delim=NULL)
 
uint32_t fileSize () const
 
uint32_t firstBlock () const
 
uint32_t firstSector () const
 
void flush ()
 
void fsetpos (const fspos_t *pos)
 
bool getAccessDate (uint16_t *pdate)
 
bool getAccessDateTime (uint16_t *pdate, uint16_t *ptime)
 
bool getCreateDateTime (uint16_t *pdate, uint16_t *ptime)
 
uint8_t getError ()
 
bool getModifyDateTime (uint16_t *pdate, uint16_t *ptime)
 
bool getName (char *name, size_t size)
 
bool getSFN (char *name)
 
bool getWriteError ()
 
bool isContiguous () const
 
bool isDir () const
 
bool isFile () const
 
bool isHidden () const
 
bool isLFN () const
 
bool isOpen () const
 
bool isReadable () const
 
bool isReadOnly () const
 
bool isRoot () const
 
bool isRoot32 () const
 
bool isRootFixed () const
 
bool isSubDir () const
 
bool isSystem () const
 
bool isWritable () const
 
bool ls (print_t *pr, uint8_t flags=0, uint8_t indent=0)
 
bool ls (uint8_t flags=0)
 
bool mkdir (FatFile *dir, const char *path, bool pFlag=true)
 
bool open (const char *path, oflag_t oflag=0X00)
 
bool open (FatFile *dirFile, const char *path, oflag_t oflag)
 
bool open (FatFile *dirFile, uint16_t index, oflag_t oflag)
 
bool open (FatVolume *vol, const char *path, oflag_t oflag)
 
bool openNext (FatFile *dirFile, oflag_t oflag=0X00)
 
bool openRoot (FatVolume *vol)
 
 operator bool ()
 
int peek ()
 
bool preAllocate (uint32_t length)
 
size_t printAccessDate (print_t *pr)
 
size_t printAccessDateTime (print_t *pr)
 
size_t printCreateDateTime (print_t *pr)
 
size_t printField (double value, char term, uint8_t prec=2)
 
size_t printField (float value, char term, uint8_t prec=2)
 
template<typename Type >
size_t printField (Type value, char term)
 
size_t printFileSize (print_t *pr)
 
size_t printModifyDateTime (print_t *pr)
 
size_t printName ()
 
size_t printName (print_t *pr)
 
size_t printSFN (print_t *pr)
 
int read ()
 
int read (void *buf, size_t count)
 
int8_t readDir (DirFat_t *dir)
 
bool remove ()
 
bool remove (const char *path)
 
bool rename (const char *newPath)
 
bool rename (FatFile *dirFile, const char *newPath)
 
void rewind ()
 
bool rmdir ()
 
bool rmRfStar ()
 
bool seekCur (int32_t offset)
 
bool seekEnd (int32_t offset=0)
 
bool seekSet (uint32_t pos)
 
bool sync ()
 
bool timestamp (uint8_t flags, uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
 
bool truncate ()
 
bool truncate (uint32_t length)
 
size_t write (const char *str)
 
size_t write (const void *buf, size_t count)
 
size_t write (uint8_t b)
 

Static Public Member Functions

static bool legal83Char (uint8_t c)
 
static void printFatDate (print_t *pr, uint16_t fatDate)
 
static void printFatTime (print_t *pr, uint16_t fatTime)
 

Friends

class FatVolume
 

Detailed Description

Basic file class.

Constructor & Destructor Documentation

◆ FatFile() [1/2]

FatFile::FatFile ( )
inline

Create an instance.

◆ FatFile() [2/2]

FatFile::FatFile ( const char *  path,
oflag_t  oflag 
)
inline

Create a file object and open it in the current working directory.

Parameters
[in]pathA path for a file to be opened.
[in]oflagValues for oflag are constructed by a bitwise-inclusive OR of open flags. see FatFile::open(FatFile*, const char*, uint8_t).

Member Function Documentation

◆ available()

int FatFile::available ( )
inline
Returns
The number of bytes available from the current position to EOF for normal files. INT_MAX is returned for very large files.

available64() is recomended for very large files.

Zero is returned for directory files.

◆ available32()

uint32_t FatFile::available32 ( )
inline
Returns
The number of bytes available from the current position to EOF for normal files. Zero is returned for directory files.

◆ clearError()

void FatFile::clearError ( )
inline

Clear all error bits.

◆ clearWriteError()

void FatFile::clearWriteError ( )
inline

Set writeError to zero

◆ close()

bool FatFile::close ( )

Close a file and force cached data and directory information to be written to the storage device.

Returns
true for success or false for failure.

◆ contiguousRange()

bool FatFile::contiguousRange ( uint32_t *  bgnSector,
uint32_t *  endSector 
)

Check for contiguous file and return its raw sector range.

Parameters
[out]bgnSectorthe first sector address for the file.
[out]endSectorthe last sector address for the file.

Set the contiguous flag if the file is contiguous. The parameters may be nullptr to only set the flag.

Returns
true for success or false for failure.

◆ createContiguous() [1/2]

bool FatFile::createContiguous ( const char *  path,
uint32_t  size 
)

Create and open a new contiguous file of a specified size.

Parameters
[in]pathA path with a valid file name.
[in]sizeThe desired file size.
Returns
true for success or false for failure.

◆ createContiguous() [2/2]

bool FatFile::createContiguous ( FatFile dirFile,
const char *  path,
uint32_t  size 
)

Create and open a new contiguous file of a specified size.

Parameters
[in]dirFileThe directory where the file will be created.
[in]pathA path with a valid file name.
[in]sizeThe desired file size.
Returns
true for success or false for failure.

◆ curCluster()

uint32_t FatFile::curCluster ( ) const
inline
Returns
The current cluster number for a file or directory.

◆ curPosition()

uint32_t FatFile::curPosition ( ) const
inline
Returns
The current position for a file or directory.

◆ dirEntry()

bool FatFile::dirEntry ( DirFat_t *  dir)

Return a file's directory entry.

Parameters
[out]dirLocation for return of the file's directory entry.
Returns
true for success or false for failure.

◆ dirIndex()

uint16_t FatFile::dirIndex ( )
inline
Returns
Directory entry index.

◆ dirSize()

uint32_t FatFile::dirSize ( )
Returns
The number of bytes allocated to a directory or zero if an error occurs.

◆ dmpFile()

void FatFile::dmpFile ( print_t pr,
uint32_t  pos,
size_t  n 
)

Dump file in Hex

Parameters
[in]prPrint stream for list.
[in]posStart position in file.
[in]nnumber of locations to dump.

◆ exists()

bool FatFile::exists ( const char *  path)
inline

Test for the existence of a file in a directory

Parameters
[in]pathPath of the file to be tested for.

The calling instance must be an open directory file.

dirFile.exists("TOFIND.TXT") searches for "TOFIND.TXT" in the directory dirFile.

Returns
True if the file exists.

◆ fgetpos()

void FatFile::fgetpos ( fspos_t *  pos)

get position for streams

Parameters
[out]posstruct to receive position

◆ fgets()

int FatFile::fgets ( char *  str,
int  num,
char *  delim = NULL 
)

Get a string from a file.

fgets() reads bytes from a file into the array pointed to by str, until num - 1 bytes are read, or a delimiter is read and transferred to str, or end-of-file is encountered. The string is then terminated with a null byte.

fgets() deletes CR, '\r', from the string. This insures only a '\n' terminates the string for Windows text files which use CRLF for newline.

Parameters
[out]strPointer to the array where the string is stored.
[in]numMaximum number of characters to be read (including the final null byte). Usually the length of the array str is used.
[in]delimOptional set of delimiters. The default is "\n".
Returns
For success fgets() returns the length of the string in str. If no data is read, fgets() returns zero for EOF or -1 if an error occurred.

◆ fileSize()

uint32_t FatFile::fileSize ( ) const
inline
Returns
The total number of bytes in a file.

◆ firstBlock()

uint32_t FatFile::firstBlock ( ) const
inline
Returns
first sector of file or zero for empty file.

◆ firstSector()

uint32_t FatFile::firstSector ( ) const
Returns
Address of first sector or zero for empty file.

◆ flush()

void FatFile::flush ( )
inline

Arduino name for sync()

◆ fsetpos()

void FatFile::fsetpos ( const fspos_t *  pos)

set position for streams

Parameters
[in]posstruct with value for new position

◆ getAccessDate()

bool FatFile::getAccessDate ( uint16_t *  pdate)

Get a file's access date.

Parameters
[out]pdatePacked date for directory entry.
Returns
true for success or false for failure.

◆ getAccessDateTime()

bool FatFile::getAccessDateTime ( uint16_t *  pdate,
uint16_t *  ptime 
)
inline

Get a file's access date and time.

Parameters
[out]pdatePacked date for directory entry.
[out]ptimereturn zero since FAT has no time.

This function is for comparability in FsFile.

Returns
true for success or false for failure.

◆ getCreateDateTime()

bool FatFile::getCreateDateTime ( uint16_t *  pdate,
uint16_t *  ptime 
)

Get a file's create date and time.

Parameters
[out]pdatePacked date for directory entry.
[out]ptimePacked time for directory entry.
Returns
true for success or false for failure.

◆ getError()

uint8_t FatFile::getError ( )
inline
Returns
All error bits.

◆ getModifyDateTime()

bool FatFile::getModifyDateTime ( uint16_t *  pdate,
uint16_t *  ptime 
)

Get a file's modify date and time.

Parameters
[out]pdatePacked date for directory entry.
[out]ptimePacked time for directory entry.
Returns
true for success or false for failure.

◆ getName()

bool FatFile::getName ( char *  name,
size_t  size 
)

Get a file's name followed by a zero byte.

Parameters
[out]nameAn array of characters for the file's name.
[in]sizeThe size of the array in bytes. The array must be at least 13 bytes long. The file's name will be truncated if the file's name is too long.
Returns
true for success or false for failure.

◆ getSFN()

bool FatFile::getSFN ( char *  name)

Get a file's Short File Name followed by a zero byte.

Parameters
[out]nameAn array of characters for the file's name. The array must be at least 13 bytes long.
Returns
true for success or false for failure.

◆ getWriteError()

bool FatFile::getWriteError ( )
inline
Returns
value of writeError

◆ isContiguous()

bool FatFile::isContiguous ( ) const
inline
Returns
True if the file is contiguous.

◆ isDir()

bool FatFile::isDir ( ) const
inline
Returns
True if this is a directory.

◆ isFile()

bool FatFile::isFile ( ) const
inline
Returns
True if this is a normal file.

◆ isHidden()

bool FatFile::isHidden ( ) const
inline
Returns
True if this is a hidden file.

◆ isLFN()

bool FatFile::isLFN ( ) const
inline
Returns
true if this file has a Long File Name.

◆ isOpen()

bool FatFile::isOpen ( ) const
inline
Returns
True if this is an open file/directory.

◆ isReadable()

bool FatFile::isReadable ( ) const
inline
Returns
True file is writable.

◆ isReadOnly()

bool FatFile::isReadOnly ( ) const
inline
Returns
True if file is read-only

◆ isRoot()

bool FatFile::isRoot ( ) const
inline
Returns
True if this is the root directory.

◆ isRoot32()

bool FatFile::isRoot32 ( ) const
inline
Returns
True if this is the FAT32 root directory.

◆ isRootFixed()

bool FatFile::isRootFixed ( ) const
inline
Returns
True if this is the FAT12 of FAT16 root directory.

◆ isSubDir()

bool FatFile::isSubDir ( ) const
inline
Returns
True if this is a subdirectory.

◆ isSystem()

bool FatFile::isSystem ( ) const
inline
Returns
True if this is a system file.

◆ isWritable()

bool FatFile::isWritable ( ) const
inline
Returns
True file is writable.

◆ legal83Char()

static bool FatFile::legal83Char ( uint8_t  c)
inlinestatic

Check for a legal 8.3 character.

Parameters
[in]cCharacter to be checked.
Returns
true for a legal 8.3 character.

◆ ls() [1/2]

bool FatFile::ls ( print_t pr,
uint8_t  flags = 0,
uint8_t  indent = 0 
)

List directory contents.

Parameters
[in]prPrint stream for list.
[in]flagsThe inclusive OR of

LS_DATE - Print file modification date

LS_SIZE - Print file size.

LS_R - Recursive list of subdirectories.

Parameters
[in]indentAmount of space before file name. Used for recursive list to indicate subdirectory level.
Returns
true for success or false for failure.

◆ ls() [2/2]

bool FatFile::ls ( uint8_t  flags = 0)
inline

List directory contents.

Parameters
[in]flagsThe inclusive OR of

LS_DATE - Print file modification date

LS_SIZE - Print file size.

LS_R - Recursive list of subdirectories.

Returns
true for success or false for failure.

◆ mkdir()

bool FatFile::mkdir ( FatFile dir,
const char *  path,
bool  pFlag = true 
)

Make a new directory.

Parameters
[in]dirAn open FatFile instance for the directory that will contain the new directory.
[in]pathA path with a valid name for the new directory.
[in]pFlagCreate missing parent directories if true.
Returns
true for success or false for failure.

◆ open() [1/4]

bool FatFile::open ( const char *  path,
oflag_t  oflag = 0X00 
)

Open a file in the current working volume.

Parameters
[in]pathA path with a valid name for a file to be opened.
[in]oflagbitwise-inclusive OR of open flags. See see FatFile::open(FatFile*, const char*, uint8_t).
Returns
true for success or false for failure.

◆ open() [2/4]

bool FatFile::open ( FatFile dirFile,
const char *  path,
oflag_t  oflag 
)

Open a file or directory by name.

Parameters
[in]dirFileAn open FatFile instance for the directory containing the file to be opened.
[in]pathA path with a valid name for a file to be opened.
[in]oflagValues for oflag are constructed by a bitwise-inclusive OR of flags from the following list. Only one of O_RDONLY, O_READ, O_WRONLY, O_WRITE, or O_RDWR is allowed.

O_RDONLY - Open for reading.

O_READ - Same as O_RDONLY.

O_WRONLY - Open for writing.

O_WRITE - Same as O_WRONLY.

O_RDWR - Open for reading and writing.

O_APPEND - If set, the file offset shall be set to the end of the file prior to each write.

O_AT_END - Set the initial position at the end of the file.

O_CREAT - If the file exists, this flag has no effect except as noted under O_EXCL below. Otherwise, the file shall be created

O_EXCL - If O_CREAT and O_EXCL are set, open() shall fail if the file exists.

O_TRUNC - If the file exists and is a regular file, and the file is successfully opened and is not read only, its length shall be truncated to 0.

WARNING: A given file must not be opened by more than one FatFile object or file corruption may occur.

Note
Directory files must be opened read only. Write and truncation is not allowed for directory files.
Returns
true for success or false for failure.

◆ open() [3/4]

bool FatFile::open ( FatFile dirFile,
uint16_t  index,
oflag_t  oflag 
)

Open a file by index.

Parameters
[in]dirFileAn open FatFile instance for the directory.
[in]indexThe index of the directory entry for the file to be opened. The value for index is (directory file position)/32.
[in]oflagbitwise-inclusive OR of open flags. See see FatFile::open(FatFile*, const char*, uint8_t).

See open() by path for definition of flags.

Returns
true for success or false for failure.

◆ open() [4/4]

bool FatFile::open ( FatVolume vol,
const char *  path,
oflag_t  oflag 
)

Open a file in the volume root directory.

Parameters
[in]volVolume where the file is located.
[in]pathwith a valid name for a file to be opened.
[in]oflagbitwise-inclusive OR of open flags. See see FatFile::open(FatFile*, const char*, uint8_t).
Returns
true for success or false for failure.

◆ openNext()

bool FatFile::openNext ( FatFile dirFile,
oflag_t  oflag = 0X00 
)

Open the next file or subdirectory in a directory.

Parameters
[in]dirFileAn open FatFile instance for the directory containing the file to be opened.
[in]oflagbitwise-inclusive OR of open flags. See see FatFile::open(FatFile*, const char*, uint8_t).
Returns
true for success or false for failure.

◆ openRoot()

bool FatFile::openRoot ( FatVolume vol)

Open a volume's root directory.

Parameters
[in]volThe FAT volume containing the root directory to be opened.
Returns
true for success or false for failure.

◆ operator bool()

FatFile::operator bool ( )
inline

The parenthesis operator.

Returns
true if a file is open.

◆ peek()

int FatFile::peek ( )

Return the next available byte without consuming it.

Returns
The byte if no error and not at eof else -1;

◆ preAllocate()

bool FatFile::preAllocate ( uint32_t  length)

Allocate contiguous clusters to an empty file.

The file must be empty with no clusters allocated.

The file will contain uninitialized data.

Parameters
[in]lengthsize of the file in bytes.
Returns
true for success or false for failure.

◆ printAccessDate()

size_t FatFile::printAccessDate ( print_t pr)

Print a file's access date

Parameters
[in]prPrint stream for output.
Returns
The number of characters printed.

◆ printAccessDateTime()

size_t FatFile::printAccessDateTime ( print_t pr)
inline

Print a file's access date

Parameters
[in]prPrint stream for output.
Returns
The number of characters printed.

◆ printCreateDateTime()

size_t FatFile::printCreateDateTime ( print_t pr)

Print a file's creation date and time

Parameters
[in]prPrint stream for output.
Returns
The number of bytes printed.

◆ printFatDate()

static void FatFile::printFatDate ( print_t pr,
uint16_t  fatDate 
)
static

Print a directory date field.

Format is yyyy-mm-dd.

Parameters
[in]prPrint stream for output.
[in]fatDateThe date field from a directory entry.

◆ printFatTime()

static void FatFile::printFatTime ( print_t pr,
uint16_t  fatTime 
)
static

Print a directory time field.

Format is hh:mm:ss.

Parameters
[in]prPrint stream for output.
[in]fatTimeThe time field from a directory entry.

◆ printField() [1/3]

size_t FatFile::printField ( double  value,
char  term,
uint8_t  prec = 2 
)
inline

Print a number followed by a field terminator.

Parameters
[in]valueThe number to be printed.
[in]termThe field terminator. Use '\n' for CR LF.
[in]precNumber of digits after decimal point.
Returns
The number of bytes written or -1 if an error occurs.

◆ printField() [2/3]

size_t FatFile::printField ( float  value,
char  term,
uint8_t  prec = 2 
)
inline

Print a number followed by a field terminator.

Parameters
[in]valueThe number to be printed.
[in]termThe field terminator. Use '\n' for CR LF.
[in]precNumber of digits after decimal point.
Returns
The number of bytes written or -1 if an error occurs.

◆ printField() [3/3]

template<typename Type >
size_t FatFile::printField ( Type  value,
char  term 
)
inline

Print a number followed by a field terminator.

Parameters
[in]valueThe number to be printed.
[in]termThe field terminator. Use '\n' for CR LF.
Returns
The number of bytes written or -1 if an error occurs.

◆ printFileSize()

size_t FatFile::printFileSize ( print_t pr)

Print a file's size.

Parameters
[in]prPrint stream for output.
Returns
The number of characters printed is returned for success and zero is returned for failure.

◆ printModifyDateTime()

size_t FatFile::printModifyDateTime ( print_t pr)

Print a file's modify date and time

Parameters
[in]prPrint stream for output.
Returns
The number of characters printed.

◆ printName() [1/2]

size_t FatFile::printName ( )
inline

Print a file's name.

Returns
true for success or false for failure.

◆ printName() [2/2]

size_t FatFile::printName ( print_t pr)

Print a file's name

Parameters
[in]prPrint stream for output.
Returns
true for success or false for failure.

◆ printSFN()

size_t FatFile::printSFN ( print_t pr)

Print a file's Short File Name.

Parameters
[in]prPrint stream for output.
Returns
The number of characters printed is returned for success and zero is returned for failure.

◆ read() [1/2]

int FatFile::read ( )
inline

Read the next byte from a file.

Returns
For success read returns the next byte in the file as an int. If an error occurs or end of file is reached -1 is returned.

◆ read() [2/2]

int FatFile::read ( void *  buf,
size_t  count 
)

Read data from a file starting at the current position.

Parameters
[out]bufPointer to the location that will receive the data.
[in]countMaximum number of bytes to read.
Returns
For success read() returns the number of bytes read. A value less than nbyte, including zero, will be returned if end of file is reached. If an error occurs, read() returns -1.

◆ readDir()

int8_t FatFile::readDir ( DirFat_t *  dir)

Read the next directory entry from a directory file.

Parameters
[out]dirThe DirFat_t struct that will receive the data.
Returns
For success readDir() returns the number of bytes read. A value of zero will be returned if end of file is reached. If an error occurs, readDir() returns -1. Possible errors include readDir() called before a directory has been opened, this is not a directory file or an I/O error occurred.

◆ remove() [1/2]

bool FatFile::remove ( )

Remove a file.

The directory entry and all data for the file are deleted.

Note
This function should not be used to delete the 8.3 version of a file that has a long name. For example if a file has the long name "New Text Document.txt" you should not delete the 8.3 name "NEWTEX~1.TXT".
Returns
true for success or false for failure.

◆ remove() [2/2]

bool FatFile::remove ( const char *  path)

Remove a file.

The directory entry and all data for the file are deleted.

Parameters
[in]pathPath for the file to be removed.

Example use: dirFile.remove(filenameToRemove);

Note
This function should not be used to delete the 8.3 version of a file that has a long name. For example if a file has the long name "New Text Document.txt" you should not delete the 8.3 name "NEWTEX~1.TXT".
Returns
true for success or false for failure.

◆ rename() [1/2]

bool FatFile::rename ( const char *  newPath)

Rename a file or subdirectory.

Note
the renamed file will be moved to the current volume working directory.
Parameters
[in]newPathNew path name for the file/directory.
Returns
true for success or false for failure.

◆ rename() [2/2]

bool FatFile::rename ( FatFile dirFile,
const char *  newPath 
)

Rename a file or subdirectory.

Parameters
[in]dirFileDirectory for the new path.
[in]newPathNew path name for the file/directory.
Returns
true for success or false for failure.

◆ rewind()

void FatFile::rewind ( )
inline

Set the file's current position to zero.

◆ rmdir()

bool FatFile::rmdir ( )

Remove a directory file.

The directory file will be removed only if it is empty and is not the root directory. rmdir() follows DOS and Windows and ignores the read-only attribute for the directory.

Note
This function should not be used to delete the 8.3 version of a directory that has a long name. For example if a directory has the long name "New folder" you should not delete the 8.3 name "NEWFOL~1".
Returns
true for success or false for failure.

◆ rmRfStar()

bool FatFile::rmRfStar ( )

Recursively delete a directory and all contained files.

This is like the Unix/Linux 'rm -rf *' if called with the root directory hence the name.

Warning - This will remove all contents of the directory including subdirectories. The directory will then be removed if it is not root. The read-only attribute for files will be ignored.

Note
This function should not be used to delete the 8.3 version of a directory that has a long name. See remove() and rmdir().
Returns
true for success or false for failure.

◆ seekCur()

bool FatFile::seekCur ( int32_t  offset)
inline

Set the files position to current position + pos. See seekSet().

Parameters
[in]offsetThe new position in bytes from the current position.
Returns
true for success or false for failure.

◆ seekEnd()

bool FatFile::seekEnd ( int32_t  offset = 0)
inline

Set the files position to end-of-file + offset. See seekSet(). Can't be used for directory files since file size is not defined.

Parameters
[in]offsetThe new position in bytes from end-of-file.
Returns
true for success or false for failure.

◆ seekSet()

bool FatFile::seekSet ( uint32_t  pos)

Sets a file's position.

Parameters
[in]posThe new position in bytes from the beginning of the file.
Returns
true for success or false for failure.

◆ sync()

bool FatFile::sync ( )

The sync() call causes all modified data and directory fields to be written to the storage device.

Returns
true for success or false for failure.

◆ timestamp()

bool FatFile::timestamp ( uint8_t  flags,
uint16_t  year,
uint8_t  month,
uint8_t  day,
uint8_t  hour,
uint8_t  minute,
uint8_t  second 
)

Set a file's timestamps in its directory entry.

Parameters
[in]flagsValues for flags are constructed by a bitwise-inclusive OR of flags from the following list

T_ACCESS - Set the file's last access date.

T_CREATE - Set the file's creation date and time.

T_WRITE - Set the file's last write/modification date and time.

Parameters
[in]yearValid range 1980 - 2107 inclusive.
[in]monthValid range 1 - 12 inclusive.
[in]dayValid range 1 - 31 inclusive.
[in]hourValid range 0 - 23 inclusive.
[in]minuteValid range 0 - 59 inclusive.
[in]secondValid range 0 - 59 inclusive
Note
It is possible to set an invalid date since there is no check for the number of days in a month.
Modify and access timestamps may be overwritten if a date time callback function has been set by dateTimeCallback().
Returns
true for success or false for failure.

◆ truncate() [1/2]

bool FatFile::truncate ( )

Truncate a file at the current file position. will be maintained if it is less than or equal to length otherwise it will be set to end of file.

Returns
true for success or false for failure.

◆ truncate() [2/2]

bool FatFile::truncate ( uint32_t  length)
inline

Truncate a file to a specified length. The current file position will be set to end of file.

Parameters
[in]lengthThe desired length for the file.
Returns
true for success or false for failure.

◆ write() [1/3]

size_t FatFile::write ( const char *  str)
inline

Write a string to a file. Used by the Arduino Print class.

Parameters
[in]strPointer to the string. Use getWriteError to check for errors.
Returns
count of characters written for success or -1 for failure.

◆ write() [2/3]

size_t FatFile::write ( const void *  buf,
size_t  count 
)

Write data to an open file.

Note
Data is moved to the cache but may not be written to the storage device until sync() is called.
Parameters
[in]bufPointer to the location of the data to be written.
[in]countNumber of bytes to write.
Returns
For success write() returns the number of bytes written, always count. If an error occurs, write() returns -1. Possible errors include write() is called before a file has been opened, write is called for a read-only file, device is full, a corrupt file system or an I/O error.

◆ write() [3/3]

size_t FatFile::write ( uint8_t  b)
inline

Write a single byte.

Parameters
[in]bThe byte to be written.
Returns
+1 for success or -1 for failure.

Friends And Related Function Documentation

◆ FatVolume

friend class FatVolume
friend

FatVolume allowed access to private members.


The documentation for this class was generated from the following files: