From 1804b13c0d4283685a7735468d274b4254a4a225 Mon Sep 17 00:00:00 2001 From: LRagji <Laukik.Ragi@gmail.com> Date: Thu, 8 Dec 2016 20:19:51 +0530 Subject: [PATCH 1/2] Added unique name generation API --- keywords.txt | 2 +- src/SD.cpp | 10 ++++++++++ src/SD.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/keywords.txt b/keywords.txt index 91e74b8..a61c952 100644 --- a/keywords.txt +++ b/keywords.txt @@ -23,7 +23,7 @@ close KEYWORD2 seek KEYWORD2 position KEYWORD2 size KEYWORD2 - +getUniqueFileName KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### diff --git a/src/SD.cpp b/src/SD.cpp index b88c665..1775be0 100644 --- a/src/SD.cpp +++ b/src/SD.cpp @@ -569,6 +569,16 @@ boolean SDClass::remove(const char *filepath) { return walkPath(filepath, root, callback_remove); } +String SDClass::getUniqueFileName(String expectedName, String expectedExtention) +{ + long counter = 0; + while (SD.exists(expectedName + String(counter) + "." + expectedExtention)) + { + counter += 1; + } + return expectedName + String(counter) + "." + expectedExtention; +} + // allows you to recurse into a directory File File::openNextFile(uint8_t mode) { diff --git a/src/SD.h b/src/SD.h index 7f41033..5d44c2f 100644 --- a/src/SD.h +++ b/src/SD.h @@ -92,6 +92,9 @@ class SDClass { boolean rmdir(const char *filepath); boolean rmdir(const String &filepath) { return rmdir(filepath.c_str()); } +//returns a unique name for the file with expectedfilename an extention. + String getUniqueFileName(String expectedName, String expectedExtention) + private: // This is used to determine the mode used to open a file From da78b2042125a1e838dc4aa91030e645e49935ee Mon Sep 17 00:00:00 2001 From: LRagji <Laukik.Ragi@gmail.com> Date: Thu, 8 Dec 2016 21:04:36 +0530 Subject: [PATCH 2/2] Fixed Compiled failure(Missing ; )!! --- keywords.txt | 2 +- src/SD.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keywords.txt b/keywords.txt index a61c952..c019f70 100644 --- a/keywords.txt +++ b/keywords.txt @@ -23,7 +23,7 @@ close KEYWORD2 seek KEYWORD2 position KEYWORD2 size KEYWORD2 -getUniqueFileName KEYWORD2 +getUniqueFileName KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### diff --git a/src/SD.h b/src/SD.h index 5d44c2f..0719e3e 100644 --- a/src/SD.h +++ b/src/SD.h @@ -93,7 +93,7 @@ class SDClass { boolean rmdir(const String &filepath) { return rmdir(filepath.c_str()); } //returns a unique name for the file with expectedfilename an extention. - String getUniqueFileName(String expectedName, String expectedExtention) + String getUniqueFileName(String expectedName, String expectedExtention); private: