Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches

Detailed Description

Kodi's file class.

Class: xbmcvfs.File(filepath, [mode])

Parameters
filepathstring Selected file path
mode[opt] string Additional mode options (if no mode is supplied, the default is Open for Read).
Mode Description
w Open for write

v19 Python API changes
Added context manager support

Example:

..
f = xbmcvfs.File(file, 'w')
..

Example (v19 and up):

..
with xbmcvfs.File(file, 'w') as f:
..
..

Function Documentation

◆ read()

read ( ...)

Function: read([bytes])


Read file parts as string.

Parameters
bytes[opt] How many bytes to read - if not set it will read the whole file
Returns
string

Example:

..
f = xbmcvfs.File(file)
b = f.read()
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as file:
b = f.read()
..

◆ readBytes()

readBytes ( ...)

Function: readBytes(numbytes)


Read bytes from file.

Parameters
numbytesHow many bytes to read [opt]- if not set it will read the whole file
Returns
bytearray

Example:

..
f = xbmcvfs.File(file)
b = f.readBytes()
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
b = f.readBytes()
..

◆ write()

write ( ...)

Function: write(buffer)


To write given data in file.

Parameters
bufferBuffer to write to file
Returns
True on success.

Example:

..
f = xbmcvfs.File(file, 'w')
result = f.write(buffer)
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file, 'w') as f:
result = f.write(buffer)
..

◆ size()

size ( )

Function: size()


Get the file size.

Returns
The file size

Example:

..
f = xbmcvfs.File(file)
s = f.size()
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
s = f.size()
..

◆ seek()

seek ( ...)

Function: seek(seekBytes, iWhence)


Seek to position in file.

Parameters
seekBytesposition in the file
iWhence[opt] where in a file to seek from[0 beginning, 1 current , 2 end position]

v19 Python API changes
Function changed. param iWhence is now optional.

Example:

..
f = xbmcvfs.File(file)
result = f.seek(8129, 0)
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
result = f.seek(8129, 0)
..

◆ tell()

tell ( )

Function: tell()


Get the current position in the file.

Returns
The file position

v19 Python API changes
New function added

Example:

..
f = xbmcvfs.File(file)
s = f.tell()
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
s = f.tell()
..

◆ close()

close ( )

Function: close()


Close opened file.


Example:

..
f = xbmcvfs.File(file)
f.close()
..

Example (v19 and up):

..
with xbmcvfs.File(file) as f:
..
..