File rename on SD-Card

Hallo

In my Sketch, i write Datalines in a File with a delay with

<FileIO.h>

File dataFile = FileSystem.open("/mnt/sda1/arduino/www/xxxxxx.txt", FILE_APPEND);

Now i want to find out how often the sketch has written into the File. Ok i will make in a Loop. But after 24 times i want to rename the file from xxxxxx.txt in xxxxxx.si1 and so on and so on.

I cant find a discription for Fileio.h with a rename class.

Can anybody help me please?

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#include <Process.h>       			
#include <FileIO.h>        			


YunServer server;				

void setup() {
  
 
server.begin();									
FileSystem.begin();       
}

void loop() {

YunClient client = server.accept();
				
	File dataFile = FileSystem.open("/mnt/sda1/arduino/www/xxxxxx.txt", FILE_APPEND);


  delay(5000); 									
}
}

Work around:

after 24 times open new file xxxxxx.siN and so on and so on.

File dataFile = FileSystem.open("/mnt/sda1/arduino/www/xxxxxx.si1", FILE_APPEND);

Hi sunnyyun

Thanks for your Solution. But for me it doesn't work, becauce the current Filename must be always the same. If i would find a command to rename the file, it would work mutch better, because if the fileio Function write with append and the file doesn't exist, it will be created.

Peter

Perseus01:
::::SNIP::::

Now i want to find out how often the sketch has written into the File. Ok i will make in a Loop. But after 24 times i want to rename the file from xxxxxx.txt in xxxxxx.si1 and so on and so on.

I cant find a discription for Fileio.h with a rename class.

Can anybody help me please?

::::SNIP::::

@Perseus01,
FileIO is a very simple library. There is NO rename. However, the filesystem is Linux you can make copy, or move. Use Process like this:

//
// Fake code only
// 

  Process.runShellCommand("cp filename.txt filename.si1")

// _OR_

  Process p;        // Create a process and call it "p"
  p.begin("mv");  
  p.addParameter("filename.txt");
  p.addParameter("filename.si1"); 
  p.run();      // Run the process and wait for its termination

SEE notes in Guide and YunProcessRunShellCommand

Jesse

Good morning jessemonroy650

Thanks for reply. I use process.h alrady in my sketch. Yout hint seems to be the solution for me.

Peter

Hi Jesse

your hint worked fine Thanks ! :slight_smile: