Renaming a file whilst in-use.

I have a project that logs most of it's actions to a log file written to an SD card.

I'd like to use a different log file name each time I power-up. I'd also like the name to be based on todays date. The problem is that the log file is opened immediately, but todays date is only available several seconds later (after the log file has been created) when the GPS module comes on line.

What I'd like to be able to do is to rename the log file after it's been opened, is this possible?

My current solution is to copy the contents of the log file to the correctly named file when the process shuts down, but this isn't ideal, it can take several seconds to copy the file, and it relies on the process achieving an orderly shutdown (rather than crashing out somewhere)

Any suggestions?

thanks

It should not be working, because it would be wrong. When you (for example) find a trick to do this, it might not work when the SD library is updated.

Using a tempory file seems to me the best option. When you use a new and unique filename for the tempory file at every startup, the data is kept when it didn't close properly.

Could you close the tempory file, and rename it, and after that open it and start appending new log messages to it. It might take some time and during that you can not log new messages.

You could create two log files. Start with the tempory file and change to another file after the date is known. After that rename the first file. That would create two files, for example: "14082801.log" and "14082802.log". You could even check for those file at startup and increase the last two digits when you restart a few times a day.
Now that I think if this, it is not a nice solution.

After that rename the first file

Is there a simple way to do a rename? Currently I have been doing it manually, i.e. I open the existing file, create a new (blank) file with the desired name and then read the old file line-by line, and then copy each line into the new file, finally I delete the original file. Not very efficient.

Could you close the tempory file, and rename it,

This might be the best way. The date is normally available after about 20 seconds, at this point the log file is rarely more than a dozen lines long. If I do the copy/rename process at this point, then it should only take a few milliseconds because the file is so small.