Multiple files, Ethernet Shield

I’ve got a very simple question, that hasn’t been answered so far.

I’m using:
-arduino Mega
-ethernet shield with sd card slot
-RFID-RC522

I want to build a webpage for an project. And I want it to show some data the arduino collects by reading RFID tags. (my HTML isn’t that well. but when this is fixed I’ll let someone else build the page.)
and write the information to a .txt file called TAG.txt.

so I want to have a total of 4 .htm files running and 1 .txt file at the same time.

The problem I encounter is, I can’t find a way to open all 3 .htm files. I’ve read somewhere you can have 2 (or more?) files open at once. But I don’t know how.

the RFID part is not yet included in the program. I’m gonna insert both programs in a new one later.

//EthernetShield
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 112); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

File webFile;
File myFile;

void setup()
{
  pinMode(10, OUTPUT); //enables SPI or disables Ethernet_Chip
  digitalWrite(10, HIGH);

  Serial.begin(9600);   // Initiate a serial communication

  // initialize SD card
  Serial.println("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println("ERROR - SD card initialization failed!");
    return;    // init failed
  }
  Serial.println("SUCCESS - SD card initialized.");

  // check for front.htm file
  if (!SD.exists("front.htm")) {
    Serial.println("ERROR - Can't find front.htm file!");
    return;  // can't find front.htm file
  }
  Serial.println("SUCCESS - Found front.htm file.");

  // check for second.htm file
  if (!SD.exists("second.htm")) {
    Serial.println("ERROR - Can't find second.htm file!");
    return;  // can't find second.htm file
  }
  Serial.println("SUCCESS - Found second.htm file.");

  // check for info.htm file
  if (!SD.exists("info.htm")) {
    Serial.println("ERROR - Can't find info.htm file!");
    return;  // can't find front.htm file
  }
  Serial.println("SUCCESS - Found info.htm file.");

  // check for uid.htm file
  if (!SD.exists("uid.htm")) {
    Serial.println("ERROR - Can't find uid.htm file!");
    return;  // can't find uid.htm file
  }
  Serial.println("SUCCESS - Found uid.htm file.");





  //TAG file, Where the TAG's will be printed
  myFile = SD.open("TAG.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to TAG.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening TAG.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("TAG.txt");
  if (myFile) {
    Serial.println("TAG.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening TAG.txt");
  }
  //Ethernet
  Ethernet.begin(mac, ip);  // initialize Ethernet device
  server.begin();           // start to listen for clients
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}
void loop()
{
  Ethernet_();
}
void Ethernet_() {
  EthernetClient client = server.available();  // try to get client

  if (client) {  // got client?
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {   // client data available to read
        char c = client.read(); // read 1 byte (character) from client
        // last line of client request is blank and ends with \n
        // respond to client only after last line received
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");
          client.println();
          //client.print("<meta http-equiv=\"refresh\" content=\"5\">");

          // send web page
          webFile = SD.open("front.htm");
          if (webFile) {
            while (webFile.available()) {
              client.write(webFile.read()); // send web page to client
            }
            webFile.close();
          }
          break;
        }
        // every line of text received from the client ends with \r\n
        if (c == '\n') {
          // last character on line of received text
          // starting new line with next character read
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // a text character was received from client
          currentLineIsBlank = false;
        }
      } // end if (client.available())
    } // end while (client.connected())
    delay(1);      // give the web browser time to receive the data
    client.stop(); // close the connection
  } // end if (client)
}

so, is this even possible?

Is it necessary to have all files open at once? I have server code that will return a bunch of files. The client requests them as needed.
http://playground.arduino.cc/Code/WebServerST
Feel free to steal what you need.

SurferTim:
Is it necessary to have all files open at once? I have server code that will return a bunch of files. The client requests them as needed.
http://playground.arduino.cc/Code/WebServerST
Feel free to steal what you need.

looks like a lot of work, understanding and using your code.

thats why I'm asking is there an easier way

Sure there is an easier way. Unfortunately there wouldn't be any error checking. You can cut that out of my code if you dare. Nobody said this was simple.

SurferTim:
You can cut that out of my code if you dare. Nobody said this was simple.g.

could you explain a little bit about you code, like where would I address the multiple files?

SurferTim:
Sure there is an easier way.

could you point me towards the right direction?

You can search around the forum, but I use the code in the link I posted. It is complex, but there is no other way to do it correctly.