Kodi Documentation
Kodi is an open source media player and entertainment hub.
Library - xbmcvfs

Virtual file system functions on Kodi. More...

Collaboration diagram for Library - xbmcvfs:

Modules

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

Functions

 copy (...)
 { xbmcvfs.copy(source, destination) } Copy file to destination, returns true/false. More...
 
 delete (...)
 { xbmcvfs.delete(file) } Delete a file More...
 
 rename (...)
 { xbmcvfs.rename(file, newFileName) } Rename a file More...
 
 exists (...)
 { xbmcvfs.exists(path) } Check for a file or folder existence More...
 
 makeLegalFilename (...)
 { xbmcvfs.makeLegalFilename(filename) } Returns a legal filename or path as a string. More...
 
 translatePath (...)
 { xbmcvfs.translatePath(path) } Returns the translated path. More...
 
 validatePath (...)
 { xbmcvfs.validatePath(path) } Returns the validated path. More...
 
 mkdir (...)
 { xbmcvfs.mkdir(path) } Create a folder. More...
 
 mkdirs (...)
 { xbmcvfs.mkdirs(path) } Make all directories along the path More...
 
 rmdir (...)
 { xbmcvfs.rmdir(path, [force]) } Remove a folder. More...
 
 listdir (...)
 { xbmcvfs.listdir(path) } Lists content of a folder. More...
 

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.

Function Documentation

◆ copy()

copy (   ...)

{ 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 (   ...)

{ xbmcvfs.delete(file) } Delete a file

Parameters
fileFile to delete
Returns
True if successed

Example:

..
xbmcvfs.delete(file)
..

◆ exists()

exists (   ...)

{ 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)
..

◆ listdir()

listdir (   ...)

{ xbmcvfs.listdir(path) } Lists content of a folder.

Parameters
pathFolder to get list from
Returns
Directory content list

Example:

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

◆ makeLegalFilename()

makeLegalFilename (   ...)

{ 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).

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
..

◆ mkdir()

mkdir (   ...)

{ xbmcvfs.mkdir(path) } Create a folder.

Parameters
pathFolder to create
Returns
True if successed

Example:

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

◆ mkdirs()

mkdirs (   ...)

{ 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)
..

◆ rename()

rename (   ...)

{ 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)
..

◆ rmdir()

rmdir (   ...)

{ 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)
..

◆ translatePath()

translatePath (   ...)

{ 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.

New function added (replaces old xbmc.translatePath)

Example:

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

◆ validatePath()

validatePath (   ...)

{ 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:').

New function added (replaces old xbmc.validatePath)

Example:

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