Kodi Development  20.0
for Binary and Script based Add-Ons
2. File functions

Detailed Description

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

Function Documentation

◆ FileExists()

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

#include <kodi/Filesystem.h>
...
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 ATTRIBUTE_HIDDEN FileExists(const std::string &filename, bool usecache=false)
Check if a file exists.
Definition: Filesystem.h:940
exists(...)
<h4><code><span style="font-style: italic;">Function: </span><span style="font-style: bold;"><font co...

◆ StatFile()

bool ATTRIBUTE_HIDDEN kodi::vfs::StatFile ( const std::string &  filename,
kodi::vfs::FileStatus 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 class FileStatus 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, trur is returned. On error, false is returned

The following table contains values that can be set with class FileStatus :

Name Type Set call Get call
ID of device containing file uint32_t SetDeviceId GetDeviceId
Represent file serial numbers uint64_t SetFileSerialNumber GetFileSerialNumber
Total size, in bytes uint64_t SetSize GetSize
Time of last access time_t SetAccessTime GetAccessTime
Time of last modification time_t SetModificationTime GetModificationTime
Time of last status change time_t SetStatusTime GetStatusTime
Stat url is a directory bool SetIsDirectory GetIsDirectory
Stat url as a symbolic link bool SetIsSymLink GetIsSymLink
Stat url as a block special bool SetIsBlock GetIsBlock
Stat url as a character special bool SetIsCharacter GetIsCharacter
Stat url as a FIFO special bool SetIsFifo GetIsFifo
Stat url as a regular bool SetIsRegular GetIsRegular
Stat url as a socket bool SetIsSocket GetIsSocket

Example:

#include <kodi/Filesystem.h>
...
kodi::vfs::FileStatus 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.GetDeviceId(),
statFile.GetSize(),
statFile.GetAccessTime(),
statFile.GetModificationTime(),
statFile.GetStatusTime(),
statFile.GetIsDirectory() ? "true" : "false",
statFile.GetIsSymLink() ? "true" : "false",
ret);
bool ATTRIBUTE_HIDDEN StatFile(const std::string &filename, kodi::vfs::FileStatus &buffer)
Get file status.
Definition: Filesystem.h:995

◆ DeleteFile()

bool ATTRIBUTE_HIDDEN 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/Filesystem.h>
#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 ATTRIBUTE_HIDDEN 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: FileBrowser.h:105
bool ATTRIBUTE_HIDDEN 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: Keyboard.h:74
bool ATTRIBUTE_HIDDEN DeleteFile(const std::string &filename)
Deletes a file.
Definition: Filesystem.h:1033

◆ RenameFile()

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

◆ CopyFile()

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