Arduino SD.exists()

Description

  • The SD.exists() function checks if a directory or file exists or not on the SD card.

Syntax

SD.exists(directory)

SD.exists(filename)

Parameters

  • directory: the name of the directory to check for existence, which can include parent directories (delimited by forward-slashes, /). Allowed type: const char array
  • filename: the name of the file to check for existence, which can include directories (delimited by forward-slashes, /). Allowed type: const char array

Returns

  • true if the file or directory exists.
  • false if the file or directory does NOT exists.

Example Code

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/reference/library/arduino-sd.exists */ #include <SD.h> #define PIN_SPI_CS 4 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.exists("arduino.txt")) Serial.println("arduino.txt doesn't exist on SD Card"); else Serial.println("arduino.txt exists on SD Card"); } void loop() { }

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.

※ OUR MESSAGES