Hardware Reference
In-Depth Information
Folders and i les are handled differently. When creating a i le, you must “open”
the i le, and the Arduino will create the i le if it does not exist. This does not
work for folders; you must i rst create the folder before creating the i le.
To create a folder, use
mkdir()
.
result = SD.mkdir(folder);
This function returns
true
if the folder was created, or
false
if the operation
did not succeed. It takes a string as a parameter and is the folder to be created
(complete with forward slashes). It can also create intermediate folders if required:
SD.mkdir("/data/sensors/temperature"); //Will create all folders
To remove a folder, use
rmdir()
.
result = SD.rmdir(folder);
This deletes the folder from the i lesystem but only on the condition that it
is empty. The function returns
true
if the folder were deleted, or
false
if it did
not complete the operation.
Folders are, in fact, special i les. They can be opened with
open()
, but to know
if a “i le” is a regular i le or a directory, you can use the
isDirectory()
function.
result = file.isDirectory();
This function takes no parameters and returns a boolean;
true
if the i le is a
folder, and
false
if the i le is a regular i le.
Card Operations
Data is buffered; that is to say that when the sketch is told to save data, that
data is not necessarily written to the SD card immediately. Because SD cards
have an embedded controller, write operations can be queued and the actual
write can be performed a few seconds later. When the SD embedded controller
receives multiple write operations, later write operations are often delayed until
the card has i nished current operations. To force all data to be written to a i le,
use
flush()
.
flush(file);
This operation is also called automatically when a i le is closed with
close()
.
Search WWH ::
Custom Search