Unverified Commit fa9e0590 authored by Dirk Carstensen's avatar Dirk Carstensen Committed by GitHub

getNextFileName: Get info whether filename is a file or directory (#8079)

re-submit #8068
parent d601c897
......@@ -203,6 +203,15 @@ String File::getNextFileName(void)
}
String File::getNextFileName(bool *isDir)
{
if (!_p) {
return "";
}
return _p->getNextFileName(isDir);
}
void File::rewindDirectory(void)
{
if (!*this) {
......
......@@ -81,6 +81,7 @@ public:
boolean seekDir(long position);
File openNextFile(const char* mode = FILE_READ);
String getNextFileName(void);
String getNextFileName(boolean *isDir);
void rewindDirectory(void);
protected:
......
......@@ -45,6 +45,7 @@ public:
virtual FileImplPtr openNextFile(const char* mode) = 0;
virtual boolean seekDir(long position);
virtual String getNextFileName(void);
virtual String getNextFileName(bool *isDir);
virtual void rewindDirectory(void) = 0;
virtual operator bool() = 0;
};
......
......@@ -540,6 +540,32 @@ String VFSFileImpl::getNextFileName()
return name;
}
String VFSFileImpl::getNextFileName(bool *isDir)
{
if (!_isDirectory || !_d) {
return "";
}
struct dirent *file = readdir(_d);
if (file == NULL) {
return "";
}
if (file->d_type != DT_REG && file->d_type != DT_DIR) {
return "";
}
String fname = String(file->d_name);
String name = String(_path);
if (!fname.startsWith("/") && !name.endsWith("/")) {
name += "/";
}
name += fname;
// check entry is a directory
if (isDir) {
*isDir = (file->d_type == DT_DIR);
}
return name;
}
void VFSFileImpl::rewindDirectory(void)
{
if(!_isDirectory || !_d) {
......
......@@ -73,6 +73,7 @@ public:
boolean isDirectory(void) override;
boolean seekDir(long position) override;
String getNextFileName(void) override;
String getNextFileName(bool *isDir) override;
FileImplPtr openNextFile(const char* mode) override;
void rewindDirectory(void) override;
operator bool();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment