Filename for SD from .txt file from SD

Hello!

I want to make a file on the SD card (Ethernet shield) with a filename that is stored on a txt file on the same SD.

I’ve tried several things but i can’t get it to work;

Read the txt file and put the name in to a int and convert this int to a char with itoa. but then i get a random number instead of a name. Is it even possible to put characters in a int?
Tried to put the output of filename.read() in to the SD.open() like this: datafile= SD.open(filename.read());. but that isn’t possible becouse you cant define a filename from a int.

Does anybody knows how to do this? Or is this not possible?

Thanks in advance!

iegj:
Read the txt file and put the name in to a int and convert this int to a char with itoa.

I can't begin to imagine why you would consider doing this.

When you mention a 'txt' file, does that mean an ascii text file? How is the file name stored within your 'txt' file, i.e. what is the format??

i am doing this because i am developing a monitoring system witch is applied to more than one Arduino, so i don't have to change the code on every Arduino, but i can change the file on the SD if i want to change the filename of the file that is send to my FTP server.

The format in the .TXT file is just the name of the file i want to create, for example: test.txt

Thanks in Advance

iegj:
i am doing this because ...

You misunderstand. What baffled me was the process you described of converting strings to integers to chars, which made no sense whatsoever.

iegj:
The format in the .TXT file is just the name of the file i want to create, for example: test.txt

In that case, read the string from the file and use that as the file name.

I have tried that but you can't assign a string as a filename, it gives an error that it has to be a character array. Also when i want to put the content from the .txt file in a string with
"
FileName = SD.open("name.txt");
if (FileName) {

while (FileName.available()) {
filename(FileName.read());
}
"
and i read the string out with "Serial.println(filename);" i get a number instead of the name "arduino1" witch is in de .txt file..

What am i doing wrong?

I have tried that but you can’t assign a string as a filename, it gives an error that it has to be a character array.

A string IS a NULL terminated array of chars. A String, on the other hand, is an abomination. Which are you referring to in your snippets?

Also when i want to put the content from the .txt file in a string with

Well, it should be pretty obvious that that won’t work. You can only assign ONE element of the array at a time.

    byte index = 0;
    while (FileName.available())
    {
       filename[index++] = FileName.read();
       filename[index] = '\0';
    }

Snippets-r-us is down the internet a ways. Post ALL of your code here, or go there, instead. Your choice.

Thanks Paul, I got it working with that!