Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
2. File functions

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

Functions

bool ATTR_DLL_LOCAL kodi::vfs::FileExists (const std::string &filename, bool usecache=false)
 Check if a file exists.
 
bool ATTR_DLL_LOCAL kodi::vfs::StatFile (const std::string &filename, kodi::vfs::FileStatus &buffer)
 Get file status.
 
bool ATTR_DLL_LOCAL kodi::vfs::DeleteFile (const std::string &filename)
 Deletes a file.
 
bool ATTR_DLL_LOCAL kodi::vfs::RenameFile (const std::string &filename, const std::string &newFileName)
 Rename a file name.
 
bool ATTR_DLL_LOCAL kodi::vfs::CopyFile (const std::string &filename, const std::string &destination)
 Copy a file from source to destination.
 

Detailed Description

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

Function Documentation

◆ CopyFile()

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

◆ DeleteFile()

bool ATTR_DLL_LOCAL 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;
if (kodi::gui::DialogFileBrowser::ShowAndGetFile("local", "",
"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, "successfully done.");
}
bool ATTR_DLL_LOCAL DeleteFile(const std::string &filename)
Deletes a file.
Definition addons/kodi-dev-kit/include/kodi/Filesystem.h:1038

◆ FileExists()

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

◆ RenameFile()

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

@ingroup cpp_kodi_vfs_Defs_FileStatus

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:

...
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 ATTR_DLL_LOCAL StatFile(const std::string &filename, kodi::vfs::FileStatus &buffer)
Get file status.
Definition addons/kodi-dev-kit/include/kodi/Filesystem.h:1000