vdip1 method for reading file count after restart

So I've finally figured out my big snafu with the vdip1 and I'm able to log to it. I haven't been able to figure out using cts rts yet but that will be another post.

If I run this code:

#include <AFSoftSerial.h>

int incomingByte=0;
int fileNumber=1;
int noOfChars;
long int valToWrite;
char activityToLog;
long int x;
long int startLogTime = 0;

#define rxPin 2
#define txPin 3

AFSoftSerial vSerial = AFSoftSerial(rxPin, txPin);

void setup() {
        Serial.begin(9600);
  
      vSerial.begin(9600);                    // opens serial port, sets data rate to 9600 bps
        vSerial.print("IPA");                  // sets the vdip to use ascii numbers (so I can read them in the code easily!)
        vSerial.print(13, BYTE);               // return character to tell vdip its end of message
        delay(10000);  //10 seconds to init the disk before writing (some disks may take longer)

}

void loop() {


  vSerial.print("OPW LOG%");                  // open to write creates a file - named
  vSerial.print(fileNumber);                  // LOG%1.TXT first time round - .TXT is for the computer
  vSerial.print(".TXT");                      // I have used the % sign in the name so I can search the disk for log files that it has created so as not to overwrite any that may be on already
  vSerial.print(13, BYTE);                    // return character

  delay(1000);
  
 vSerial.print("WRF ");               //write to file (file needs to have been opened to write first)
 vSerial.print(6);            //needs to then be told how many characters will be written
 vSerial.print(13, BYTE);             //return to say command is finished
 vSerial.print("123456");        //followed by the info to write
 vSerial.print(13, BYTE);             //write a return to the contents of the file (so each entry appears on a new line)
 delay(1000);
  vSerial.print("CLF LOG%");     // it closes the file
  vSerial.print(fileNumber);     // LOG%1.TXT
  vSerial.print(".TXT");
  vSerial.print(13, BYTE);       // return character

 // fileNumber++;                                    //so we can create other files
  
  delay(10000);
  get_file_num();
  
}

void get_file_num(){ 
   vSerial.print("DIR");
   vSerial.print(13, BYTE);
   delay(1000);  //wait a second
   
   while (char i = vSerial.read()){ //umlauted ÿ should be check character...ie hex 98 or dec 152
     Serial.print(i); //debug to serial monitor on IDE
     if (i == '%'){
      fileNumber = vSerial.read() + 1; //should work, but might have to convert to int and back
     }
     /*if (i == 'D'){  //if we get a D that isn't a D:\ then exit because that is the last log#
       if (vSerial.read() != ':'){
         if (vSerial.read() != '\\'){
           return;
         }
       }
     }*/
   }
   
   delay(10000);
}

I get this output (via the serial monitor on the ide):
D:>
D:>
D:>
D:>
D:>

DISK.
TRASHE~1 DIR
_~1.TRA
LOG%.TXT
Dÿÿÿÿ

The 'ÿ' repeats indefinitely. I attempted to use this character as the test for the end of the file listing, but that didn't work and I got the same output via the serial monitor. Perhaps I need to test for something else.

I could always store a file count in the eeprom, but that is problematic for several reasons (I'm almost out of sketch space and adding a lib doesn't help, plus I'm not sure I want to wear out the EEPROM so fast).

I am also contemplating storing a file number in a file called "f" and using that for file counts. I'm kind of afraid of the overhead of this transaction though.

In addition I'm not sure that doing a DIR will show the log files in numerical order. So I might not be looking for the last file listed with "%" in it.

I'm running the alt software serial lib because I intend to integrate this into a project that uses an lcd. I am open to switching the LCD to software serial though.

PS:

This should work but doesn't. Can someone please explain why?

   while (char i = vSerial.read()){ //umlauted ÿ should be check character...ie hex 98 or dec 152
      Serial.print(i); //debug to serial monitor on IDE
      if (i == '%'){
          fileNumber = vSerial.read() + 1; //should work, but might have to convert to int and back
      }
        if (i == 'ÿ'){
          return;
        }
   }

The Serial.print(i) returns this:

D:\>

DISK.
TRASHE~1 DIR
_~1.TRA
DS_STO~1.
_LOG%~1.TXT
LOG%.TXÿÿÿÿÿ