** Function: createNewFile ** Function will save a file into FS. If file already exists it will ** append a version number to the file name. **********************************************************************/
| 1009 | ** append a version number to the file name. |
| 1010 | **********************************************************************/ |
| 1011 | File 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 | } |
no test coverage detected