Kodi Documentation 18.0
Kodi is an open source media player and entertainment hub.
Interface - kodi::vfs

Virtual filesystem functions More...

Modules

 Definitions, structures and enumerators
 Virtual file Server definition values
 
 class CDirEntry
 Virtual file server directory entry
 
 class CFile
 Virtual file server control
 

Functions

bool kodi::vfs::CreateDirectory (const std::string &path)
 Make a directory. More...
 
bool kodi::vfs::DirectoryExists (const std::string &path)
 Verifying the Existence of a Directory. More...
 
bool kodi::vfs::RemoveDirectory (const std::string &path)
 Removes a directory. More...
 
bool kodi::vfs::GetDirectory (const std::string &path, const std::string &mask, std::vector< CDirEntry > &items)
 Lists a directory. More...
 
std::string kodi::vfs::GetFileMD5 (const std::string &path)
 Retrieve MD5sum of a file. More...
 
std::string kodi::vfs::GetCacheThumbName (const std::string &filename)
 Returns a thumb cache filename. More...
 
std::string kodi::vfs::MakeLegalFileName (const std::string &filename)
 Make filename valid. More...
 
std::string kodi::vfs::MakeLegalPath (const std::string &path)
 Make directory name valid. More...
 
std::string kodi::vfs::TranslateSpecialProtocol (const std::string &source)
 Returns the translated path. More...
 
std::string kodi::vfs::GetFileName (const std::string &path)
 Return the file name from given complate path string. More...
 
std::string kodi::vfs::GetDirectoryName (const std::string &path)
 Return the directory name from given complate path string. More...
 
void kodi::vfs::RemoveSlashAtEnd (std::string &path)
 Remove the slash on given path name. More...
 
unsigned int kodi::vfs::GetChunkSize (unsigned int chunk, unsigned int minimum)
 Return a size aligned to the chunk size at least as large as the chunk size. More...
 
bool kodi::vfs::FileExists (const std::string &filename, bool usecache=false)
 Check if a file exists. More...
 
bool kodi::vfs::StatFile (const std::string &filename, STAT_STRUCTURE &buffer)
 Get file status. More...
 
bool kodi::vfs::DeleteFile (const std::string &filename)
 Deletes a file. More...
 
bool kodi::vfs::RenameFile (const std::string &filename, const std::string &newFileName)
 Rename a file name. More...
 
bool kodi::vfs::CopyFile (const std::string &filename, const std::string &destination)
 Copy a file from source to destination. More...
 

Detailed Description

Virtual filesystem functions

It has the header #include <kodi/Filesystem.h> be included to enjoy it.

Function Documentation

◆ CopyFile()

bool kodi::vfs::CopyFile ( const std::string &  filename,
const std::string &  destination 
)
inline

Copy a file from source to destination.

Parameters
[in]filenameThe filename to copy.
[in]destinationThe destination to copy file to
Returns
true if successfully copied

◆ CreateDirectory()

bool 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:

...
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 CreateDirectory(const std::string &path)
Make a directory.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:557

◆ DeleteFile()

bool kodi::vfs::DeleteFile ( const std::string &  filename)
inline

Deletes a file.

Parameters
[in]filenameThe filename to delete.
Returns
The file was successfully deleted.

Example:

#include <kodi/gui/DialogFileBrowser.h>
#include <kodi/gui/DialogOK.h>
...
std::string filename;
"Test File selection and delete of them!",
filename))
{
bool successed = kodi::vfs::DeleteFile(filename);
if (!successed)
kodi::gui::DialogOK::ShowAndGetInput("Error", "Delete of File", filename, "failed!");
else
kodi::gui::DialogOK::ShowAndGetInput("Information", "Delete of File", filename, "successfull done.");
}
bool ShowAndGetFile(const std::string &shares, const std::string &mask, const std::string &heading, std::string &path, bool useThumbs=false, bool useFileDirectories=false)
File selection dialog.
Definition: kodi-addon-dev-kit/include/kodi/gui/dialogs/FileBrowser.h:107
bool ShowAndGetInput(std::string &text, const std::string &heading, bool allowEmptyResult, bool hiddenInput=false, unsigned int autoCloseMs=0)
Show keyboard with initial value text and replace with result string.
Definition: addons/kodi-addon-dev-kit/include/kodi/gui/dialogs/Keyboard.h:79
bool DeleteFile(const std::string &filename)
Deletes a file.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:1136

◆ DirectoryExists()

bool 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:

...
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 DirectoryExists(const std::string &path)
Verifying the Existence of a Directory.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:587

◆ FileExists()

bool kodi::vfs::FileExists ( const std::string &  filename,
bool  usecache = false 
)
inline

Check if a file exists.

Parameters
[in]filenameThe filename to check.
[in]usecacheCheck in file cache.
Returns
true if the file exists false otherwise.

Example:

...
bool exists = kodi::vfs::FileExists("special://temp/kodi.log");
fprintf(stderr, "Log file should be always present, is it present? %s\n", exists ? "yes" : "no");
bool FileExists(const std::string &filename, bool usecache=false)
Check if a file exists.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:1020
exists(...)
Check for a file or folder existence.

◆ GetCacheThumbName()

std::string kodi::vfs::GetCacheThumbName ( const std::string &  filename)
inline

Returns a thumb cache filename.

Parameters
[in]filenamepath to file
Returns
cache filename

Example:

#include <kodi/gui/DialogFileBrowser.h>
...
std::string thumb;
std::string filename;
if (kodi::gui::DialogFileBrowser::ShowAndGetFile("local", "*.avi|*.mpg|*.mp4",
"Test File selection to get Thumnail",
filename))
{
thumb = kodi::vfs::GetCacheThumbName(filename);
fprintf(stderr, "Thumb name of file '%s' is %s\n", thumb.c_str(), filename.c_str());
}
std::string GetCacheThumbName(const std::string &filename)
Returns a thumb cache filename.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:749

◆ GetChunkSize()

unsigned int kodi::vfs::GetChunkSize ( unsigned int  chunk,
unsigned int  minimum 
)
inline

Return a size aligned to the chunk size at least as large as the chunk size.

Parameters
[in]chunkThe chunk size
[in]minimumThe minimum size (or maybe the minimum number of chunks?)
Returns
The aligned size

◆ GetDirectory()

bool kodi::vfs::GetDirectory ( const std::string &  path,
const std::string &  mask,
std::vector< 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:

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 GetDirectory(const std::string &path, const std::string &mask, std::vector< CDirEntry > &items)
Lists a directory.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:661

◆ GetDirectoryName()

std::string kodi::vfs::GetDirectoryName ( const std::string &  path)
inline

Return the directory name from given complate path string.

Parameters
[in]pathThe complete path include file and directory
Returns
Directory name from path

Example:

...
std::string dirName = kodi::vfs::GetDirectoryName("special://temp/kodi.log");
fprintf(stderr, "Directory name is '%s'\n", dirName.c_str());
std::string GetDirectoryName(const std::string &path)
Return the directory name from given complate path string.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:934

◆ GetFileMD5()

std::string kodi::vfs::GetFileMD5 ( const std::string &  path)
inline

Retrieve MD5sum of a file.

Parameters
[in]pathpath to the file to MD5sum
Returns
md5 sum of the file

Example:

#include <kodi/gui/DialogFileBrowser.h>
...
std::string md5;
std::string filename;
if (kodi::gui::DialogFileBrowser::ShowAndGetFile("local", "*.avi|*.mpg|*.mp4",
"Test File selection to get MD5",
filename))
{
md5 = kodi::vfs::GetFileMD5(filename);
fprintf(stderr, "MD5 of file '%s' is %s\n", md5.c_str(), filename.c_str());
}
std::string GetFileMD5(const std::string &path)
Retrieve MD5sum of a file.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:708

◆ GetFileName()

std::string kodi::vfs::GetFileName ( const std::string &  path)
inline

Return the file name from given complate path string.

Parameters
[in]pathThe complete path include file and directory
Returns
Filename from path

Example:

...
std::string fileName = kodi::vfs::GetFileName("special://temp/kodi.log");
fprintf(stderr, "File name is '%s'\n", fileName.c_str());
std::string GetFileName(const std::string &path)
Return the file name from given complate path string.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:907

◆ MakeLegalFileName()

std::string kodi::vfs::MakeLegalFileName ( const std::string &  filename)
inline

Make filename valid.

Function to replace not valid characters with '_'. It can be also compared with original before in a own loop until it is equal (no invalid characters).

Parameters
[in]filenameFilename to check and fix
Returns
The legal filename

Example:

...
std::string fileName = "///\\jk???lj????.mpg";
std::string legalName = kodi::vfs::MakeLegalFileName(fileName);
fprintf(stderr, "Legal name of '%s' is '%s'\n", fileName.c_str(), legalName.c_str());
/* Returns as legal: 'jk___lj____.mpg' *&zwj;/
std::string MakeLegalFileName(const std::string &filename)
Make filename valid.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:789

◆ MakeLegalPath()

std::string kodi::vfs::MakeLegalPath ( const std::string &  path)
inline

Make directory name valid.

Function to replace not valid characters with '_'. It can be also compared with original before in a own loop until it is equal (no invalid characters).

Parameters
[in]pathDirectory name to check and fix
Returns
The legal directory name

Example:

...
std::string path = "///\\jk???lj????\\hgjkg";
std::string legalPath = kodi::vfs::MakeLegalPath(path);
fprintf(stderr, "Legal name of '%s' is '%s'\n", path.c_str(), legalPath.c_str());
/* Returns as legal: '/jk___lj____/hgjkg' *&zwj;/
std::string MakeLegalPath(const std::string &path)
Make directory name valid.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:829

◆ RemoveDirectory()

bool kodi::vfs::RemoveDirectory ( const std::string &  path)
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.
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:

...
bool ret = kodi::vfs::RemoveDirectory("C:\\my_dir");
...
bool RemoveDirectory(const std::string &path)
Removes a directory.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:618

◆ RemoveSlashAtEnd()

void kodi::vfs::RemoveSlashAtEnd ( std::string &  path)
inline

Remove the slash on given path name.

Parameters
[in,out]pathThe complete path

Example:

...
std::string dirName = "special://temp/";
fprintf(stderr, "Directory name is '%s'\n", dirName.c_str());
void RemoveSlashAtEnd(std::string &path)
Remove the slash on given path name.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:971

◆ RenameFile()

bool kodi::vfs::RenameFile ( const std::string &  filename,
const std::string &  newFileName 
)
inline

Rename a file name.

Parameters
[in]filenameThe filename to copy.
[in]newFileNameThe new filename
Returns
true if successfully renamed

◆ StatFile()

bool kodi::vfs::StatFile ( const std::string &  filename,
STAT_STRUCTURE buffer 
)
inline

Get file status.

These function return information about a file. Execute (search) permission is required on all of the directories in path that lead to the file.

The call return a stat structure, which contains the on STAT_STRUCTURE defined values.

Warning
Not all of the OS file systems implement all of the time fields.
Parameters
[in]filenameThe filename to read the status from.
[out]bufferThe file status is written into this buffer.
Returns
On success, tru is returned. On error, fale is returned

Example:

...
STAT_STRUCTURE statFile;
int ret = kodi::vfs::StatFile("special://temp/kodi.log", statFile);
fprintf(stderr, "deviceId (ID of device containing file) = %u\n"
"size (total size, in bytes) = %lu\n"
"accessTime (time of last access) = %lu\n"
"modificationTime (time of last modification) = %lu\n"
"statusTime (time of last status change) = %lu\n"
"isDirectory (The stat url is a directory) = %s\n"
"isSymLink (The stat url is a symbolic link) = %s\n"
"Return value = %i\n",
statFile.deviceId,
statFile.size,
statFile.accessTime,
statFile.modificationTime,
statFile.statusTime,
statFile.isDirectory ? "true" : "false",
statFile.isSymLink ? "true" : "false",
ret);
bool StatFile(const std::string &filename, STAT_STRUCTURE &buffer)
Get file status.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:1071

◆ TranslateSpecialProtocol()

std::string kodi::vfs::TranslateSpecialProtocol ( const std::string &  source)
inline

Returns the translated path.

Parameters
[in]sourcestring or unicode - Path to format
Returns
A human-readable string suitable for logging
Note
Only useful if you are coding for both Linux and Windows. e.g. Converts 'special://masterprofile/script_data' -> '/home/user/.kodi/UserData/script_data' on Linux.

Example:

...
std::string path = kodi::vfs::TranslateSpecialProtocol("special://masterprofile/script_data");
fprintf(stderr, "Translated path is: %s\n", path.c_str());
...
std::string TranslateSpecialProtocol(const std::string &source)
Returns the translated path.
Definition: addons/kodi-addon-dev-kit/include/kodi/Filesystem.h:874

or

...
fprintf(stderr, "Directory 'special://temp' is '%s'\n", kodi::vfs::TranslateSpecialProtocol("special://temp").c_str());
...