Kodi's file class.
Class: xbmcvfs.File(filepath, [mode])
- Parameters
-
filepath | string 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:
..
..
◆ 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()
Function: readBytes(numbytes)
Read bytes from file.
- Parameters
-
numbytes | How 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()
Function: write(buffer)
To write given data in file.
- Parameters
-
buffer | Buffer 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()
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()
Function: seek(seekBytes, iWhence)
Seek to position in file.
- Parameters
-
seekBytes | position 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()
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()
Function: close()
Close opened file.
Example:
..
f = xbmcvfs.File(file)
f.close()
..
Example (v19 and up):
..
with xbmcvfs.File(file) as f:
..
..