1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00

Implement SPIFFS.exists

This commit is contained in:
Ivan Grokhotkov 2015-09-14 12:46:47 +03:00
parent f73d414f38
commit c8b12fd72c
5 changed files with 32 additions and 1 deletions

View File

@ -193,6 +193,17 @@ File FS::open(const char* path, const char* mode) {
return File(_impl->open(path, om, am));
}
bool FS::exists(const char* path) {
if (!_impl) {
return false;
}
return _impl->exists(path);
}
bool FS::exists(const String& path) {
return exists(path.c_str());
}
Dir FS::openDir(const char* path) {
if (!_impl) {
return Dir();

View File

@ -97,6 +97,9 @@ public:
File open(const char* path, const char* mode);
File open(const String& path, const char* mode);
bool exists(const char* path);
bool exists(const String& path);
Dir openDir(const char* path);
Dir openDir(const String& path);

View File

@ -65,6 +65,7 @@ public:
virtual bool begin() = 0;
virtual bool format() = 0;
virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0;
virtual bool exists(const char* path) = 0;
virtual DirImplPtr openDir(const char* path) = 0;
virtual bool rename(const char* pathFrom, const char* pathTo) = 0;
virtual bool remove(const char* path) = 0;

View File

@ -59,7 +59,7 @@ public:
}
FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) override;
bool exists(const char* path) override;
DirImplPtr openDir(const char* path) override;
bool rename(const char* pathFrom, const char* pathTo) override {
@ -404,6 +404,14 @@ FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode acc
return std::make_shared<SPIFFSFileImpl>(this, fd);
}
bool SPIFFSImpl::exists(const char* path) {
char tmpName[SPIFFS_OBJ_NAME_LEN];
strlcpy(tmpName, path, sizeof(tmpName));
spiffs_stat stat;
int rc = SPIFFS_stat(&_fs, tmpName, &stat);
return rc == SPIFFS_OK;
}
DirImplPtr SPIFFSImpl::openDir(const char* path) {
spiffs_DIR dir;
char tmpName[SPIFFS_OBJ_NAME_LEN];

View File

@ -191,6 +191,14 @@ if (!f) {
}
```
#### exists
```c++
SPIFFS.exists(path)
```
Returns *true* if a file with given path exists, *false* otherwise.
#### openDir
```c++