Kodi Development  20.0
for Binary and Script based Add-Ons
Library - xbmcvfs

Detailed Description

Virtual file system functions on Kodi.

Offers classes and functions offers access to the Virtual File Server (VFS) which you can use to manipulate files and folders.

Modules

 File
 Kodi's file class.
 
 Stat
 Get file or file system status.
 

Function Documentation

◆ copy()

copy (   ...)

Function: xbmcvfs.copy(source, destination)


Copy file to destination, returns true/false.

Parameters
sourcefile to copy.
destinationdestination file
Returns
True if successed

Example:

..
success = xbmcvfs.copy(source, destination)
..

◆ delete()

delete (   ...)

Function: xbmcvfs.delete(file)


Delete a file

Parameters
fileFile to delete
Returns
True if successed

Example:

..
xbmcvfs.delete(file)
..

◆ rename()

rename (   ...)

Function: xbmcvfs.rename(file, newFileName)


Rename a file

Parameters
fileFile to rename
newFileNameNew filename, including the full path
Returns
True if successed
Note
Moving files between different filesystem (eg. local to nfs://) is not possible on all platforms. You may have to do it manually by using the copy and deleteFile functions.

Example:

..
success = xbmcvfs.rename(file,newFileName)
..

◆ exists()

exists (   ...)

Function: xbmcvfs.exists(path)


Check for a file or folder existence

Parameters
pathFile or folder (folder must end with slash or backslash)
Returns
True if successed

Example:

..
success = xbmcvfs.exists(path)
..

◆ makeLegalFilename()

makeLegalFilename (   ...)

Function: xbmcvfs.makeLegalFilename(filename)


Returns a legal filename or path as a string.

Parameters
filenamestring - filename/path to make legal
Returns
Legal filename or path as a string
Note
The returned value is platform-specific. This is due to the fact that the chars that need to be replaced to make a path legal depend on the underlying OS filesystem. This is useful, for example, if you want to create a file or folder based on data over which you have no control (e.g. an external API).

v19 Python API changes:
New function added (replaces old xbmc.makeLegalFilename)

Example:

..
# windows
>> xbmcvfs.makeLegalFilename('C://Trailers/Ice Age: The Meltdown.avi')
C:\Trailers\Ice Age_ The Meltdown.avi
# non-windows
>> xbmcvfs.makeLegalFilename("///\\jk???lj????.mpg")
/jk___lj____.mpg
..

◆ translatePath()

translatePath (   ...)

Function: xbmcvfs.translatePath(path)


Returns the translated path.

Parameters
pathstring - Path to format
Returns
Translated path
Note
Only useful if you are coding for both Linux and Windows. e.g. Converts 'special://home' -> '/home/[username]/.kodi' on Linux.

v19 Python API changes:
New function added (replaces old xbmc.translatePath)

Example:

..
fpath = xbmcvfs.translatePath('special://home')
..

◆ validatePath()

validatePath (   ...)

Function: xbmcvfs.validatePath(path)


Returns the validated path.

Parameters
pathstring - Path to format
Returns
Validated path
Note
The result is platform-specific. Only useful if you are coding for multiple platfforms for fixing slash problems (e.g. Corrects 'Z://something' -> 'Z:\something').

v19 Python API changes:
New function added (replaces old xbmc.validatePath)

Example:

..
fpath = xbmcvfs.validatePath(somepath)
..

◆ mkdir()

mkdir (   ...)

Function: xbmcvfs.mkdir(path)


Create a folder.

Parameters
pathFolder to create
Returns
True if successed

Example:

..
success = xbmcvfs.mkdir(path)
..

◆ mkdirs()

mkdirs (   ...)

Function: xbmcvfs.mkdirs(path)


Make all directories along the path

Create folder(s) - it will create all folders in the path.

Parameters
pathFolders to create
Returns
True if successed

Example:

..
success = xbmcvfs.mkdirs(path)
..

◆ rmdir()

rmdir (   ...)

Function: xbmcvfs.rmdir(path, [force])


Remove a folder.

Parameters
pathstring - Folder to remove
force[opt] bool - Force directory removal (default False). This can be useful if the directory is not empty.
Returns
bool - True if successful, False otherwise

Example:

..
success = xbmcvfs.rmdir(path)
..

◆ listdir()

listdir (   ...)

Function: xbmcvfs.listdir(path)


Lists content of a folder.

Parameters
pathFolder to get list from
Returns
Directory content list

Example:

..
dirs, files = xbmcvfs.listdir(path)
..