Help with combining 2 sketches together.

What I am saying is that if the condition is not met only that one line will be missed. I would have thought if you can not open the file you do not want to read from it.

if (Serial.available() > 0)
  {

    incomingByte = Serial.read();
    if (incomingByte == 'R')
    {
      Serial.begin(115200);
      if (!myFile.open("codes.txt", O_READ))
      Serial.println("code.txt:");  // miss this if the file is not open and do the rest of the lines
      int data;
      while ((data = myFile.read()) > 0) Serial.write(data);
      // close the file:
      myFile.close();
      
      }