Arduino SD.mkdir()
Description
The SD.mkdir() function creates a directory on the SD card. This will also create any intermediate directories if they don't already exists. For example, SD.mkdir("arduino/library/SD") will create arduino, library, and SD.
Syntax
SD.mkdir(filename)
Parameters
- filename: the name of the directory to create, with sub-directories separated by forward-slashes, /
Returns
- true: if the directory is created successfully.
- false: if the directory is NOT created successfully.
Example Code
/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/reference/library/arduino-sd.mkdir
*/
#include <SD.h>
#define PIN_SPI_CS 4
File file;
void setup() {
Serial.begin(9600);
if (!SD.begin(PIN_SPI_CS)) {
Serial.println("SD CARD FAILED, OR NOT PRESENT!");
while (1); // don't do anything more:
}
if (SD.mkdir("arduino/log"))
Serial.println("Created arduino/log directory");
else
Serial.println("Failed to create arduino/log directory");
}
void loop() {
}
Tutorials
See Also
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.