Input/Output to/from local file system.
Error codes returned from methods in this module will correspond to the ErrNo module.

Availability

Script Types
Extension, Interface

open()

Open a file; similar to Lua’s io.open method.

Usage

local f = open("hello.txt", 'rt') -- only read text

Parameters

Return value

A File Object


mkdir()

Similar to mkdir(2); creates a directory.

Usage

local c1, c2 = vlc.io.mkdir("/this/path/might/exist/folder_name")
if c1 == -1 then -- operation failed
	if c2 == vlc.errno.EACCES then
		print("Oh no: No permission")
	else
		print("Some error occurred!")
else
	print("All's good!")
end

Parameters

Return value

Two integer values:


readdir()

List all files and folders in a given directory.

Usage

local files_in_dir = vlc.io.readdir("/path/to/existing/directory/")
for i,f in pairs(files_in_dir) do
	vlc.msg.info("File #" .. i .. " in directory is: " .. f)
end

Parameters

Return value

List of file/folder names (empty if directory is empty)


Similar to os.remove; unlinks/removes a file.

Parameters

Return value

Two integer values:


File Modes

To open a file, a ‘mode’ must be specified. This is done via strings where the modes and modifiers are each represented by a character.

Base Modes:

Modifiers can also be added to modes to change the way they work

As an example, f = open("hello.exe", 'rt') would open, but f:read("*a") would not return all data from the file.


File Object

Represents an open file.

file:read()

Read from open file.
Throws an error if called on closed file.

Usage

local f = open("some_file_to_read.txt", 'rt')
local text = f:read("*a")
vlc.msg.info("There are " .. string.len(text) .. " characters in the file!")

Parameters

Return value

Either nil or a string containing the data that was read


file:write()

Write data to a file.
Throws an error if called on closed file or a file opened without write permissions.

Usage

local f = open("some_file.txt", 'a')
f:write("Hello, world!") -- append "Hello, world!"

Parameters

Return value

Boolean value: true if write operation succeeded, else false


file:seek()

Set the internal position of the file, where file data is read from and written to.
Throws an error if called on closed file.

Usage

local f = open("user_string_length.txt", 'r')
f:seek("set", 41)
vlc.msg.info("42nd character is: " .. f:read(1))

Parameters

Return value

Number specifying the new internal position


file:flush()

Flushes output buffer (calls fflush internally).


file:close()

Closes an open file.