Skip to content

Commit

Permalink
Add CardReader::fileExists
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 28, 2020
1 parent 021851c commit 53e8ed4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,16 @@ void CardReader::openFileWrite(char * const path) {
#endif
}

//
// Check if a file exists by absolute or workDir-relative path
//
bool CardReader::fileExists(const char * const path) {
if (!isMounted()) return false;
SdFile *diveDir = nullptr;
const char * const fname = diveToFile(false, diveDir, path);
return fname != nullptr;
}

//
// Delete a file by name in the working directory
//
Expand Down Expand Up @@ -820,9 +830,7 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile*& diveDir, cons
}

// Close diveDir if not at starting-point
if (diveDir != startDir) {
diveDir->close();
}
if (diveDir != startDir) diveDir->close();

// diveDir now subDir
diveDir = sub;
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/sd/cardreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class CardReader {
static void openFileRead(char * const path, const uint8_t subcall=0);
static void openFileWrite(char * const path);
static void closefile(const bool store_location=false);
static bool fileExists(const char * const name);
static void removeFile(const char * const name);

static inline char* longest_filename() { return longFilename[0] ? longFilename : filename; }
Expand Down

0 comments on commit 53e8ed4

Please sign in to comment.