SD.exists(filename) freezes


I'm trying to check if a filename exists, if it does, I save my new file with a different name. But every time i execute SD.exists("filename") the arduino just freezes.

// (This is just a cutout of the real code)
char filename[] = "TEST1.TXT";
int filename_counter  = 1;

while( SD.exists(filename) ) {                  //As long as another file by this name exists: change it
  filename_counter++;                           //Counts up the number for the file
  filename[4]=char(filename_counter);           //Edits the number in the file

Even just writing:

int a = SD.exists("1");                         //(Which shouldn't exist)

It freezes

( works just fine)

Your cutout doesn't hang when I try it.

Also this does not generate valid file names


So it will always exit the loop after the first test for "TEST1.TXT".

The code also alters a compile-time string, which is not valid C I believe...