unable to read file after deleting another.

hello guys.
First of all, in my first message, and i would like to thank you for reading and trying to help.
ill try to be as clear as i can, forgive me for my poor english.

my code is supposed to:

  1. read the content of a file.
  2. send the content over UDP
  3. delete the file.

my problem begins after deleting a file.
after running SD.remove(myFile.name()) for the first time,
**myFile = SD.open(String(i)**wont pic up the next file
*my files names are numbers [1, 2, 3, 4... etc]

I'm very frustrated and need your help.
what am i doing wrong?

int sendData()
{
  udp.begin(localPort);
  for (int i = filecount; i > 0; i--) // initiated at setup
  { myFile = SD.open(String(i));
    while (myFile.available())
    {
      udp.beginPacket(ServerIP, dstPort);
      String Data = myFile.readString();
      udp.print(Data);
      udp.endPacket();
    }
    myFile.close();
    SD.remove(myFile.name());
  }
}

What happens if you use two for loops - one to read and send the data and the other to delete the files?

PaulS:
What happens if you use two for loops - one to read and send the data and the other to delete the files?

unfortunately this produce the same error.
i narrowed the issue.
when running Serial.println(SD.exists("7")); the return is 1 (file does exists.)
but when running

char charBuf[FileName.length()];
FileName.toCharArray(charBuf, sizeof(FileName));
Serial.println(SD.exists(charBuf));

the return is 0.

i narrowed the issue.

to a mistake in your code.

If there is 1 character in the name, then the array size needs to be 2, to hold the one character and the terminating NULL.

Good going.