MCPcopy Create free account
hub / github.com/BruceDevices/firmware / createNewFile

Function createNewFile

src/core/sd_functions.cpp:1011–1031  ·  view source on GitHub ↗

** Function: createNewFile ** Function will save a file into FS. If file already exists it will ** append a version number to the file name. **********************************************************************/

Source from the content-addressed store, hash-verified

1009** append a version number to the file name.
1010**********************************************************************/
1011File createNewFile(FS *&fs, String filepath, String filename) {
1012 int extIndex = filename.lastIndexOf('.');
1013 String name = filename.substring(0, extIndex);
1014 String ext = filename.substring(extIndex);
1015
1016 if (filepath.endsWith("/")) filepath = filepath.substring(0, filepath.length() - 1);
1017 if (!(*fs).exists(filepath)) (*fs).mkdir(filepath);
1018
1019 name = filepath + "/" + name;
1020
1021 if ((*fs).exists(name + ext)) {
1022 int i = 1;
1023 name += "_";
1024 while ((*fs).exists(name + String(i) + ext)) i++;
1025 name += String(i);
1026 }
1027
1028 Serial.println("Creating file: " + name + ext);
1029 File file = (*fs).open(name + ext, FILE_WRITE);
1030 return file;
1031}

Callers 2

RCSwitch_SaveSignalFunction · 0.85
saveMethod · 0.85

Calls 1

printlnMethod · 0.45

Tested by

no test coverage detected