SapFlow Probe
A low-cost HRM probe for measuring a tree's water consumption
sd_log.cpp File Reference
#include "sd_log.h"

Go to the source code of this file.

Functions

String newfile (String fname, String suffix)
 Avoids file conflicts by renaming. More...
 

Function Documentation

◆ newfile()

String newfile ( String  fname,
String  suffix = ".csv" 
)

Avoids file conflicts by renaming.

Checks if the filename exists. If so, appends an integer. For example, if "test.csv" and "test(01).csv" are present in the file system and you call String x = newfile("test"); x will contain the string "test(02).csv"

Parameters
fnameThe desired file name (without the extension)
suffixThe file extension
Returns
the new filename it came up with.

Definition at line 5 of file sd_log.cpp.

5  {
6  String temp = fname + suffix; //< Start with the name provided
7  int i = 0;
8  // Try appending a number
9  while(sd.exists(temp.c_str())){
10  // If the first number didn't work, keep trying
11  // Note that this will hang if 00 through 99 are all taken
12  ++i;
13  char ones = i%10 + '0';
14  char tens = i/10 + '0';
15  temp = fname + '(' + tens + ones + ')' + suffix;
16  }
17  return temp;
18 }
sd
static SdFat sd
File system object.
Definition: sd_log.h:14