Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
Library - xbmcvfs

Virtual file system functions on Kodi. More...

Topics

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

Functions

 copy (...)
 

Function: xbmcvfs.copy(source, destination)


Copy file to destination, returns true/false.
 
 delete (...)
 

Function: xbmcvfs.delete(file)


Delete a file
 
 rename (...)
 

Function: xbmcvfs.rename(file, newFileName)


Rename a file
 
 exists (...)
 

Function: xbmcvfs.exists(path)


Check for a file or folder existence
 
 makeLegalFilename (...)
 

Function: xbmcvfs.makeLegalFilename(filename)


Returns a legal filename or path as a string.
 
 translatePath (...)
 

Function: xbmcvfs.translatePath(path)


Returns the translated path.
 
 validatePath (...)
 

Function: xbmcvfs.validatePath(path)


Returns the validated path.
 
 mkdir (...)
 

Function: xbmcvfs.mkdir(path)


Create a folder.
 
 mkdirs (...)
 

Function: xbmcvfs.mkdirs(path)


Make all directories along the path
 
 rmdir (...)
 

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


Remove a folder.
 
 listdir (...)
 

Function: xbmcvfs.listdir(path)


Lists content of a folder.
 

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

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

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

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

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

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

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

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

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