SdFat
|
FsBaseFile class. More...
#include <FsFile.h>
Public Member Functions | |
int | available () |
void | clearWriteError () |
bool | close () |
uint64_t | curPosition () |
uint32_t | dirIndex () |
bool | exists (const char *path) |
void | fgetpos (fspos_t *pos) |
int | fgets (char *str, int num, char *delim=nullptr) |
uint64_t | fileSize () |
void | flush () |
FsBaseFile (const FsBaseFile &from) | |
void | fsetpos (const fspos_t *pos) |
uint8_t | getError () |
size_t | getName (char *name, size_t len) |
bool | getWriteError () |
bool | isDir () |
bool | isDirectory () |
bool | isHidden () |
bool | isOpen () |
bool | isSubDir () |
bool | ls (print_t *pr) |
bool | ls (print_t *pr, uint8_t flags) |
bool | mkdir (FsBaseFile *dir, const char *path, bool pFlag=true) |
const char * | name () const |
bool | open (FsBaseFile *dir, const char *path, oflag_t oflag=O_RDONLY) |
bool | open (FsBaseFile *dir, uint32_t index, oflag_t oflag) |
bool | open (FsVolume *vol, const char *path, oflag_t oflag) |
bool | open (const char *path, oflag_t oflag=O_RDONLY) |
bool | openNext (FsBaseFile *dir, oflag_t oflag=O_RDONLY) |
operator bool () | |
FsBaseFile & | operator= (const FsBaseFile &from) |
int | peek () |
uint64_t | position () |
bool | preAllocate (uint64_t length) |
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 (print_t *pr) |
int | read () |
int | read (void *buf, size_t count) |
bool | remove () |
bool | remove (const char *path) |
bool | rename (const char *newPath) |
bool | rename (FsBaseFile *dirFile, const char *newPath) |
void | rewind () |
void | rewindDirectory () |
bool | rmdir () |
bool | seek (uint64_t pos) |
bool | seekCur (int64_t offset) |
bool | seekEnd (int64_t offset=0) |
bool | seekSet (uint64_t pos) |
uint64_t | size () |
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 (uint64_t length) |
size_t | write (uint8_t b) |
size_t | write (const void *buf, size_t count) |
FsBaseFile class.
FsBaseFile::FsBaseFile | ( | const FsBaseFile & | from | ) |
Copy constructor.
[in] | from | Object used to initialize this instance. |
Copyright (c) 2011-2019 Bill Greiman This file is part of the SdFat library for SD memory cards.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
inline |
|
inline |
Set writeError to zero
bool FsBaseFile::close | ( | ) |
Close a file and force cached data and directory information to be written to the storage device.
|
inline |
|
inline |
|
inline |
Test for the existence of a file in a directory
[in] | path | Path 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.
|
inline |
get position for streams
[out] | pos | struct to receive position |
|
inline |
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.
[out] | str | Pointer to the array where the string is stored. |
[in] | num | Maximum number of characters to be read (including the final null byte). Usually the length of the array str is used. |
[in] | delim | Optional set of delimiters. The default is "\n". |
|
inline |
|
inline |
Ensure that any bytes written to the file are saved to the SD card.
|
inline |
set position for streams
[in] | pos | struct with value for new position |
|
inline |
|
inline |
Get a file's name followed by a zero byte.
[out] | name | An array of characters for the file's name. |
[in] | len | The 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. |
|
inline |
|
inline |
|
inline |
This function reports if the current file is a directory or not.
|
inline |
|
inline |
|
inline |
|
inline |
List directory contents.
[in] | pr | Print object. |
|
inline |
List directory contents.
[in] | pr | Print object. |
[in] | flags | The inclusive OR of |
LS_DATE - Print file modification date
LS_SIZE - Print file size.
LS_R - Recursive list of subdirectories.
bool FsBaseFile::mkdir | ( | FsBaseFile * | dir, |
const char * | path, | ||
bool | pFlag = true |
||
) |
Make a new directory.
[in] | dir | An open FatFile instance for the directory that will contain the new directory. |
[in] | path | A path with a valid 8.3 DOS name for the new directory. |
[in] | pFlag | Create missing parent directories if true. |
|
inline |
No longer implemented due to Long File Names.
Use getName(char* name, size_t size).
bool FsBaseFile::open | ( | FsBaseFile * | dir, |
const char * | path, | ||
oflag_t | oflag = O_RDONLY |
||
) |
Open a file or directory by name.
[in] | dir | An open file instance for the directory containing the file to be opened. |
[in] | path | A path with a valid 8.3 DOS name for a file to be opened. |
[in] | oflag | Values for oflag are constructed by a bitwise-inclusive OR of flags from the following list |
O_RDONLY - Open for reading only..
O_READ - Same as O_RDONLY.
O_WRONLY - Open for writing only.
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 file object or file corruption may occur.
bool FsBaseFile::open | ( | FsBaseFile * | dir, |
uint32_t | index, | ||
oflag_t | oflag | ||
) |
Open a file by index.
[in] | dir | An open FsFile instance for the directory. |
[in] | index | The index of the directory entry for the file to be opened. The value for index is (directory file position)/32. |
[in] | oflag | bitwise-inclusive OR of open flags. See see FsFile::open(FsFile*, const char*, uint8_t). |
See open() by path for definition of flags.
bool FsBaseFile::open | ( | FsVolume * | vol, |
const char * | path, | ||
oflag_t | oflag | ||
) |
Open a file or directory by name.
[in] | vol | Volume where the file is located. |
[in] | path | A path for a file to be opened. |
[in] | oflag | Values for oflag are constructed by a bitwise-inclusive OR of open flags. |
|
inline |
Open a file or directory by name.
[in] | path | A path for a file to be opened. |
[in] | oflag | Values for oflag are constructed by a bitwise-inclusive OR of open flags. |
bool FsBaseFile::openNext | ( | FsBaseFile * | dir, |
oflag_t | oflag = O_RDONLY |
||
) |
Opens the next file or folder in a directory.
[in] | dir | directory containing files. |
[in] | oflag | open flags. |
|
inline |
The parenthesis operator.
FsBaseFile & FsBaseFile::operator= | ( | const FsBaseFile & | from | ) |
Copy assignment operator
[in] | from | Object used to initialize this instance. |
|
inline |
Return the next available byte without consuming it.
|
inline |
|
inline |
Allocate contiguous clusters to an empty file.
The file must be empty with no clusters allocated.
The file will contain uninitialized data for FAT16/FAT32 files. exFAT files will have zero validLength and dataLength will equal the requested length.
[in] | length | size of the file in bytes. |
|
inline |
Print a file's access date and time
[in] | pr | Print stream for output. |
|
inline |
Print a file's creation date and time
[in] | pr | Print stream for output. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. Use '\n' for CR LF. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. Use '\n' for CR LF. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. Use '\n' for CR LF. |
|
inline |
Print a file's size.
[in] | pr | Print stream for output. |
|
inline |
Print a file's modify date and time
[in] | pr | Print stream for output. |
|
inline |
Print a file's name
[in] | pr | Print stream for output. |
|
inline |
Read the next byte from a file.
|
inline |
Read data from a file starting at the current position.
[out] | buf | Pointer to the location that will receive the data. |
[in] | count | Maximum number of bytes to read. |
bool FsBaseFile::remove | ( | ) |
Remove a file.
The directory entry and all data for the file are deleted.
|
inline |
Remove a file.
The directory entry and all data for the file are deleted.
[in] | path | Path for the file to be removed. |
Example use: dirFile.remove(filenameToRemove);
|
inline |
Rename a file or subdirectory.
[in] | newPath | New path name for the file/directory. |
|
inline |
Rename a file or subdirectory.
[in] | dirFile | Directory for the new path. |
[in] | newPath | New path name for the file/directory. |
|
inline |
Set the file's current position to zero.
|
inline |
Rewind a file if it is a directory
bool FsBaseFile::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.
|
inline |
Seek to a new position in the file, which must be between 0 and the size of the file (inclusive).
[in] | pos | the new file position. |
|
inline |
Set the files position to current position + pos. See seekSet().
[in] | offset | The new position in bytes from the current position. |
|
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.
[in] | offset | The new position in bytes from end-of-file. |
|
inline |
Sets a file's position.
[in] | pos | The new position in bytes from the beginning of the file. |
|
inline |
|
inline |
The sync() call causes all modified data and directory fields to be written to the storage device.
|
inline |
Set a file's timestamps in its directory entry.
[in] | flags | Values 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.
[in] | year | Valid range 1980 - 2107 inclusive. |
[in] | month | Valid range 1 - 12 inclusive. |
[in] | day | Valid range 1 - 31 inclusive. |
[in] | hour | Valid range 0 - 23 inclusive. |
[in] | minute | Valid range 0 - 59 inclusive. |
[in] | second | Valid range 0 - 59 inclusive |
|
inline |
Truncate a file to the current position.
|
inline |
Truncate a file to a specified length. The current file position will be set to end of file.
[in] | length | The desired length for the file. |
|
inline |
Write a byte to a file. Required by the Arduino Print class.
[in] | b | the byte to be written. Use getWriteError to check for errors. |
|
inline |
Write data to an open file.
[in] | buf | Pointer to the location of the data to be written. |
[in] | count | Number of bytes to write. |