Kodi Development  20.0
for Binary and Script based Add-Ons
1. Directory functions

Detailed Description

Globally available directories related functions
Used to perform typical operations with it.

Function Documentation

◆ CreateDirectory()

bool ATTRIBUTE_HIDDEN kodi::vfs::CreateDirectory ( const std::string &  path)
inline

Make a directory.

The kodi::vfs::CreateDirectory() function shall create a new directory with name path.

The newly created directory shall be an empty directory.

Parameters
[in]pathPath to the directory.
Returns
Upon successful completion, CreateDirectory() shall return true. Otherwise false shall be returned, no directory shall be created.

Example:

#include <kodi/Filesystem.h>
...
std::string directory = "C:\\my_dir";
bool ret = kodi::vfs::CreateDirectory(directory);
fprintf(stderr, "Directory '%s' successfull created: %s\n", directory.c_str(), ret ? "yes" : "no");
...
bool ATTRIBUTE_HIDDEN CreateDirectory(const std::string &path)
Make a directory.
Definition: Filesystem.h:773

◆ DirectoryExists()

bool ATTRIBUTE_HIDDEN kodi::vfs::DirectoryExists ( const std::string &  path)
inline

Verifying the Existence of a Directory.

The kodi::vfs::DirectoryExists() method determines whether a specified folder exists.

Parameters
[in]pathPath to the directory.
Returns
True when it exists, false otherwise.

Example:

#include <kodi/Filesystem.h>
...
std::string directory = "C:\\my_dir";
bool ret = kodi::vfs::DirectoryExists(directory);
fprintf(stderr, "Directory '%s' present: %s\n", directory.c_str(), ret ? "yes" : "no");
...
bool ATTRIBUTE_HIDDEN DirectoryExists(const std::string &path)
Verifying the Existence of a Directory.
Definition: Filesystem.h:805

◆ RemoveDirectory()

bool ATTRIBUTE_HIDDEN kodi::vfs::RemoveDirectory ( const std::string &  path,
bool  recursive = false 
)
inline

Removes a directory.

The kodi::vfs::RemoveDirectory() function shall remove a directory whose name is given by path.

Parameters
[in]pathPath to the directory.
[in]recursive[opt] Remove directory recursive (default is false)
Returns
Upon successful completion, the function RemoveDirectory() shall return true. Otherwise, false shall be returned, and errno set to indicate the error. If false is returned, the named directory shall not be changed.

Example:

#include <kodi/Filesystem.h>
...
bool ret = kodi::vfs::RemoveDirectory("C:\\my_dir");
...
bool ATTRIBUTE_HIDDEN RemoveDirectory(const std::string &path, bool recursive=false)
Removes a directory.
Definition: Filesystem.h:839

◆ GetDirectory()

bool ATTRIBUTE_HIDDEN kodi::vfs::GetDirectory ( const std::string &  path,
const std::string &  mask,
std::vector< kodi::vfs::CDirEntry > &  items 
)
inline

Lists a directory.

Return the list of files and directories which have been found in the specified directory and which respect the given constraint.

It can handle the normal OS dependent paths and also the special virtual filesystem from Kodi what starts with special://.

Parameters
[in]pathThe path in which the files and directories are located.
[in]maskMask to filter out requested files, e.g. "*.avi|*.mpg" to files with this ending.
[out]itemsThe returned list directory entries.
Returns
True if listing was successful, false otherwise.

Example:

#include <kodi/Filesystem.h>
std::vector<kodi::vfs::CDirEntry> items;
kodi::vfs::GetDirectory("special://temp", "", items);
fprintf(stderr, "Directory have %lu entries\n", items.size());
for (unsigned long i = 0; i < items.size(); i++)
{
fprintf(stderr, " - %04lu -- Folder: %s -- Name: %s -- Path: %s\n",
i+1,
items[i].IsFolder() ? "yes" : "no ",
items[i].Label().c_str(),
items[i].Path().c_str());
}
bool ATTRIBUTE_HIDDEN GetDirectory(const std::string &path, const std::string &mask, std::vector< kodi::vfs::CDirEntry > &items)
Lists a directory.
Definition: Filesystem.h:888