Skip to content

Commit 1804b13

Browse files
LRagjiLRagji
authored andcommitted
Added unique name generation API
1 parent 3460b7d commit 1804b13

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ close KEYWORD2
2323
seek KEYWORD2
2424
position KEYWORD2
2525
size KEYWORD2
26-
26+
getUniqueFileName KEYWORD2
2727
#######################################
2828
# Constants (LITERAL1)
2929
#######################################

src/SD.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,16 @@ boolean SDClass::remove(const char *filepath) {
569569
return walkPath(filepath, root, callback_remove);
570570
}
571571

572+
String SDClass::getUniqueFileName(String expectedName, String expectedExtention)
573+
{
574+
long counter = 0;
575+
while (SD.exists(expectedName + String(counter) + "." + expectedExtention))
576+
{
577+
counter += 1;
578+
}
579+
return expectedName + String(counter) + "." + expectedExtention;
580+
}
581+
572582

573583
// allows you to recurse into a directory
574584
File File::openNextFile(uint8_t mode) {

src/SD.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class SDClass {
9292
boolean rmdir(const char *filepath);
9393
boolean rmdir(const String &filepath) { return rmdir(filepath.c_str()); }
9494

95+
//returns a unique name for the file with expectedfilename an extention.
96+
String getUniqueFileName(String expectedName, String expectedExtention)
97+
9598
private:
9699

97100
// This is used to determine the mode used to open a file

0 commit comments

Comments
 (0)