Arduino File.name()

Description

The File.name() function returns the name of the file.

The File.name() function inherits from the Stream utility class.

Syntax

file.name()

Returns

  • The filename of the file. Returned type: char *

Example Code

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/reference/library/arduino-file.name */ #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: } file = SD.open("arduino.txt", FILE_READ); if (file) { Serial.println(file.name()); file.close(); } else { Serial.println("SD Card: error on opening file"); } } void loop() { }
  • Open Serial Monitor, you will see as below:
COM6
Send
arduino.txt
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

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