Reading an SD card and saving the date of the latest file in a data type

Dear Arduino-fellows,

I would like to read out an SD card and save the timestamp/date of the most recent file to a datatype. All the examples provided by the Arduino SD card library:

Work fine for me.

/*
  The circuit:
    SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
     Pin 4 used here for consistency with other Arduino examples
*/

// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

//initialization check
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("Card type:         ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    while (1);
  }

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  word payload = root.ls(LS_DATE);
  Serial.println(payload);
}

void loop(void) {
}

However, due to some lack of knowledge and experience, I am not able to store the read out information from root.ls(LS_DATE) to a data type. Which data type would you suggest for storing this format:
SYSTEM~1/ 2019-09-24 13:50:14

How can I remove everything besides the date and also just save the most recent file date?

Best and thank you,
Marco

However, due to some lack of knowledge and experience, I am not able to store the read out information from root.ls(LS_DATE) to a data type. Which data type would you suggest for storing this format:
SYSTEM~1/ 2019-09-24 13:50:14

The ls() method just writes some information to the serial interface. The method doesn't return any information to the caller. So if you want to store the information you must use other methods/macros. The data type to store the information depends on what usage you have for this data. As you didn't specify that, we cannot suggest a correct data type. To store the information you provided in the post the only type that makes sense is a string but that's usually the worst type for using later.

pylon:
The ls() method just writes some information to the serial interface. The method doesn't return any information to the caller. So if you want to store the information you must use other methods/macros. The data type to store the information depends on what usage you have for this data. As you didn't specify that, we cannot suggest a correct data type. To store the information you provided in the post the only type that makes sense is a string but that's usually the worst t

pylon:
The ls() method just writes some information to the serial interface. The method doesn't return any information to the caller. So if you want to store the information you must use other methods/macros. The data type to store the information depends on what usage you have for this data. As you didn't specify that, we cannot suggest a correct data type. To store the information you provided in the post the only type that makes sense is a string but that's usually the worst type for using later.

Thank you a lot for your reply Pylon! I want to send the Data to thethingsnetwork via LoRaWAN. It is also possible to convert the format to an integer like 201910292000 for today at 20:00.

thethingsnetwork is just a LoRaWAN network provider so you cannot send it there but to some server.

There's a listfiles example in the SD library that shows how to get a file listing. The implementation of the ls() method shows how to get the detail information.