This code listens to changes to a directory and maintains a list of all JSON files in the directory.
#include <vector>
{
{ }
std::vector<limes::files::File> jsonFiles;
{
return;
{
if (fileObj->hasFileExtension (".json"))
jsonFiles.emplace_back (*fileObj);
}
}
{
jsonFiles.erase (std::find_if (jsonFiles.begin(), jsonFiles.end(),
{
return f.getAbsolutePath() == p;
}));
}
{
{
return;
}
{
if (! fileObj->hasFileExtension (".json"))
return;
const auto alreadyInList = (std::find (jsonFiles.begin(),
jsonFiles.end(),
*fileObj)
!= jsonFiles.end());
if (! alreadyInList)
jsonFiles.emplace_back (*fileObj);
}
}
};
This class represents a directory on the filesystem.
bool contains(const FilesystemEntry &entry, std::size_t depthLimit=50) const
Returns true if this directory contains the passed FilesystemEntry.
This class listens for changes to or operations on a certain file, and receives callbacks to be notif...
This class represents a file on the filesystem.
The base class for any kind of object on the filesystem.
Path getAbsolutePath(bool makePreferred=false) const noexcept
Returns the full, absolute path of this filesystem entry.
std::optional< File > getFileObject() const noexcept
If this object refers to a file, constructs a File object referring to the same file.
The main header for the limes_files library.
void fileDeleted(const limes::files::FilesystemEntry &file) final
Called when a file is deleted.
void fileCreated(const limes::files::FilesystemEntry &file) final
Called when a file or subdirectory is created in a watched directory.
void fileMoved(const limes::files::FilesystemEntry &file) final
Called when a file is moved or renamed.