SD card file creation

I want to create a new file on an SD card whenever a button is pressed. To assign new name for the file I have used the following code:
void open_file()
{
byte a=1;
String b= String(a) + ".csv";;
while(SD.exists(String b))
a=a++;
SD.open(String(a)+".csv", FILE_WRITE);
}

This is giving me an error: "expected primary expression before 'b' ".
However, when I replace String b with eg: "xps.csv", it works. I really don't get it "xps.csv is a string and why is it that I cannot use a string variable inside SD.exists??
Please help

Why do you have "String b" again in your while loop condition? I'm no expert but try just putting "b".

Thanks for that....I didn't notice it. However, I am stuck with a new error now.
"no matching function to call to 'SDClass::exists(String&)'

byte a=1;
Should this be "static" or should it be a global variable?

Revamped the code and got it working:

void open_file()
{
byte a=1;

while(a!=0)
{String b= String(a) + ".csv";
char c[b.length()+1];
b.toCharArray(c,sizeof(c));

if(!SD.exists(c))
{
data=SD.open(c, FILE_WRITE);
a=0;
}
else
{a=a++;}

}

}

The String class is making your code needlessly complex, as well as introducing the possibility of memory corruption in versions prior to 1.0.4 and heap fragmentation in all versions.

Why don't you generate the file name directly in a plain old c-string (i.e. null-terminated char array)? Just declare a char array of the maximum length of your file name and use snprintf() to generate the file name from the number. This will also give you control over leading zeroes etc, which might be useful if you want your files to be sortable alphabetically.

Once it is working you might also want to think about how you will handle or avoid the device filling up.