Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fa9e059

Browse filesBrowse files
authored
getNextFileName: Get info whether filename is a file or directory (espressif#8079)
re-submit espressif#8068
1 parent d601c89 commit fa9e059
Copy full SHA for fa9e059

File tree

Expand file treeCollapse file tree

5 files changed

+38
-0
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+38
-0
lines changed

‎libraries/FS/src/FS.cpp

Copy file name to clipboardExpand all lines: libraries/FS/src/FS.cpp
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ String File::getNextFileName(void)
203203

204204
}
205205

206+
String File::getNextFileName(bool *isDir)
207+
{
208+
if (!_p) {
209+
return "";
210+
}
211+
return _p->getNextFileName(isDir);
212+
213+
}
214+
206215
void File::rewindDirectory(void)
207216
{
208217
if (!*this) {

‎libraries/FS/src/FS.h

Copy file name to clipboardExpand all lines: libraries/FS/src/FS.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class File : public Stream
8181
boolean seekDir(long position);
8282
File openNextFile(const char* mode = FILE_READ);
8383
String getNextFileName(void);
84+
String getNextFileName(boolean *isDir);
8485
void rewindDirectory(void);
8586

8687
protected:

‎libraries/FS/src/FSImpl.h

Copy file name to clipboardExpand all lines: libraries/FS/src/FSImpl.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class FileImpl
4545
virtual FileImplPtr openNextFile(const char* mode) = 0;
4646
virtual boolean seekDir(long position);
4747
virtual String getNextFileName(void);
48+
virtual String getNextFileName(bool *isDir);
4849
virtual void rewindDirectory(void) = 0;
4950
virtual operator bool() = 0;
5051
};

‎libraries/FS/src/vfs_api.cpp

Copy file name to clipboardExpand all lines: libraries/FS/src/vfs_api.cpp
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,32 @@ String VFSFileImpl::getNextFileName()
540540
return name;
541541
}
542542

543+
String VFSFileImpl::getNextFileName(bool *isDir)
544+
{
545+
if (!_isDirectory || !_d) {
546+
return "";
547+
}
548+
struct dirent *file = readdir(_d);
549+
if (file == NULL) {
550+
return "";
551+
}
552+
if (file->d_type != DT_REG && file->d_type != DT_DIR) {
553+
return "";
554+
}
555+
String fname = String(file->d_name);
556+
String name = String(_path);
557+
if (!fname.startsWith("/") && !name.endsWith("/")) {
558+
name += "/";
559+
}
560+
name += fname;
561+
562+
// check entry is a directory
563+
if (isDir) {
564+
*isDir = (file->d_type == DT_DIR);
565+
}
566+
return name;
567+
}
568+
543569
void VFSFileImpl::rewindDirectory(void)
544570
{
545571
if(!_isDirectory || !_d) {

‎libraries/FS/src/vfs_api.h

Copy file name to clipboardExpand all lines: libraries/FS/src/vfs_api.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class VFSFileImpl : public FileImpl
7373
boolean isDirectory(void) override;
7474
boolean seekDir(long position) override;
7575
String getNextFileName(void) override;
76+
String getNextFileName(bool *isDir) override;
7677
FileImplPtr openNextFile(const char* mode) override;
7778
void rewindDirectory(void) override;
7879
operator bool();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.