LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
io

Files, folders, archives & hashes (extends Lua's io library) More...

Detailed Description

These functions are added to Lua's standard io library, so io.open(), io.read(), etc. still work like in normal Lua (see the Lua manual).

Paths on the PS Vita start with a partition, for example:

if not io.exists("ux0:data/myapp") then
io.newfolder("ux0:data/myapp")
end
local file = io.open("ux0:data/myapp/save.txt", "w")
file:write("Hello!")
file:close()

Functions

boolean io.exists (string path)
 
nil io.newfolder (string path)
 
boolean io.delete (string path)
 
boolean io.copy (string source, string destination)
 
table io.list (string path)
 
table io.info (string path)
 
string io.pathstrip (string path)
 
string io.filestrip (string path)
 
string io.workpath (string path)
 
number io.freespace (string partition)
 
number io.fullspace (string partition)
 
table io.readsfo (string path)
 
nil io.editsfo (string path, string key, string value)
 
nil io.extract (string archive, string destination)
 
boolean io.archive (string contents, string archive_path, string format)
 
number io.crc32 (string text)
 
string io.md5 (string text)
 
string io.sha1 (string text)
 
string io.sha256 (string text)
 

Function Documentation

◆ io.archive()

boolean io.archive ( string contents,
string archive_path,
string format )

Creates an archive from a folder, or from a list of files

Parameters
contentsEither a folder path (everything inside it is added), or a table where each key is a file path and each value is the name it gets inside the archive
archive_pathPath of the archive to create
formatArchive format (optional, default: "zip"). One of "zip", "7z", "gnutar", "ustar", "v7tar", "xar", "iso9660", "ar_bsd", "ar_svr4", "warc" or "raw"
Returns
true when done
Example:
io.archive("ux0:data/myapp", "ux0:data/myapp_backup.zip")
io.archive({["ux0:data/myapp/save.txt"] = "save.txt"}, "ux0:data/save.7z", "7z")

◆ io.copy()

boolean io.copy ( string source,
string destination )

Copies a file, or a folder together with everything inside it. Missing parent folders of the destination are created, and existing files are overwritten.

If you define a global function called LifeLuaCopying, it's called while copying, so you can show the progress: once when each folder is created, once when each file starts, and after every piece (64 KB) of a file is copied. It receives:

  1. string: Path of the file or folder being copied
  2. string: Path of its copy
  3. number: Bytes of this file copied so far (0 for folders)
  4. number: Size of this file in bytes (0 for folders)
  5. number: How many files and folders have been handled so far, counting this one

If the callback raises an error, copying stops (what was already copied stays) and the error is passed on.

Parameters
sourcePath of the file or folder to copy
destinationFull path of the copy, not the folder to put it in: io.copy("ux0:data/a.txt", "ux0:data/backup/a.txt"), not io.copy("ux0:data/a.txt", "ux0:data/backup")
Returns
true on success, false if the source doesn't exist or something couldn't be copied (copying stops at the first thing that fails). Raises an error if you try to copy a folder into itself.
Example:
local white = color.new(255, 255, 255)
function LifeLuaCopying(source, destination, copied, size, number)
draw.text(10, 10, "Copying #"..number..": "..source, white)
if size > 0 then draw.text(10, 40, math.floor(copied * 100 / size).."%", white) end
draw.swapbuffers()
end
io.copy("ux0:data/myapp", "ux0:data/myapp_backup")

◆ io.crc32()

number io.crc32 ( string text)

Calculates the CRC32 checksum of a text

Parameters
textThe text
Returns
The checksum as a number

◆ io.delete()

boolean io.delete ( string path)

Deletes a file, or a folder together with everything inside it

If you define a global function called LifeLuaDeleting, it's called right before each file or folder is deleted, so you can show the progress. A folder's contents are deleted before the folder itself. It receives:

  1. string: Path of the file or folder about to be deleted
  2. boolean: true if it's a folder
  3. number: How many files and folders have been handled so far, counting this one

If the callback raises an error, deleting stops (what was already deleted stays deleted) and the error is passed on.

Parameters
pathPath of the file or folder to delete
Returns
true on success, false if it doesn't exist or something couldn't be deleted (deleting stops at the first thing that fails)
Warning
Folders are deleted with everything in them, without asking. Double-check the path!
Example:
function LifeLuaDeleting(path, isafolder, number)
draw.text(10, 10, "Deleting #"..number..": "..path, color.new(255, 255, 255))
draw.swapbuffers()
end
io.delete("ux0:data/myapp/cache")

◆ io.editsfo()

nil io.editsfo ( string path,
string key,
string value )

Changes one value in a .SFO file. The key must already exist in the file.

Parameters
pathPath to the .SFO
keyKey to change (e.g. "TITLE")
valueNew value: a string for text keys, a number for number keys

◆ io.exists()

boolean io.exists ( string path)

Checks if a file or folder exists

Parameters
pathPath to check
Returns
true if it exists

◆ io.extract()

nil io.extract ( string archive,
string destination )

Extracts an archive (.ZIP, .7Z, .RAR, .TAR, .VPK, ...). Missing folders are created.

If you define a global function called LifeLuaArchiveExtracting, it's called for each file before it's extracted. You can use it to draw a progress screen.

Parameters
archivePath to the archive
destinationFolder to extract into
Example:
function LifeLuaArchiveExtracting(name, index, size)
draw.text(10, 10, "Extracting file #"..index..": "..name, color.new(255, 255, 255))
draw.swapbuffers()
end
io.extract("ux0:data/game.zip", "ux0:data/game")

◆ io.filestrip()

string io.filestrip ( string path)

Removes the last part of a path (gets the folder that contains it)

Parameters
pathA path
Returns
The parent folder, e.g. "ux0:data/myapp" for "ux0:data/myapp/save.txt"

◆ io.freespace()

number io.freespace ( string partition)

Gets the free space of a partition

Parameters
partitionPartition name (e.g. "ux0:")
Returns
Free space in bytes
Example:
print(string.format("%.2f GB free", io.freespace("ux0:") / 1024^3))

◆ io.fullspace()

number io.fullspace ( string partition)

Gets the total size of a partition

Parameters
partitionPartition name (e.g. "ux0:")
Returns
Total size in bytes

◆ io.info()

table io.info ( string path)

Gets information about a file or a folder

Parameters
pathPath of the file or folder
Returns
nil if it doesn't exist, otherwise a table with these fields:
  • boolean isafolder: true for folders
  • number size: Size in bytes
  • string created, modified, accessed: Dates in the "YYYY-MM-DD HH:MM:SS" format

◆ io.list()

table io.list ( string path)

Lists the contents of a folder

Parameters
pathPath of the folder
Returns
nil if the folder can't be opened, otherwise a list with one table per file/folder, with these fields:
  • string name: File or folder name
  • string path: Full path
  • boolean isafolder: true for folders
  • number size: Size in bytes
  • string created, modified, accessed: Dates in the "YYYY-MM-DD HH:MM:SS" format
Example:
for i, item in ipairs(io.list("ux0:data")) do
print(item.name, item.isafolder and "folder" or item.size.." bytes")
end

◆ io.md5()

string io.md5 ( string text)

Calculates the MD5 hash of a string

Parameters
textThe string (can contain any bytes)
Returns
The hash as uppercase hexadecimal text

◆ io.newfolder()

nil io.newfolder ( string path)

Creates a folder, including any missing parent folders. Does nothing if it already exists.

Parameters
pathPath of the new folder (e.g. "ux0:data/myapp/saves")

◆ io.pathstrip()

string io.pathstrip ( string path)

Gets the last part of a path (the file or folder name)

Parameters
pathA path
Returns
The name, e.g. "save.txt" for "ux0:data/myapp/save.txt"

◆ io.readsfo()

table io.readsfo ( string path)

Reads a .SFO file (like an app's sce_sys/param.sfo)

Parameters
pathPath to the .SFO
Returns
A table with every key of the .SFO, with string or number values. Raises an error if the file is invalid.
Example:
local sfo = io.readsfo("app0:sce_sys/param.sfo")
print(sfo.TITLE, sfo.TITLE_ID)

◆ io.sha1()

string io.sha1 ( string text)

Calculates the SHA-1 hash of a text

Parameters
textThe text
Returns
The hash as uppercase hexadecimal text
Example:
print(io.sha1("hello")) -- AAF4C61DDCC5E8A2DABEDE0F3B482CD9AEA9434D

◆ io.sha256()

string io.sha256 ( string text)

Calculates the SHA-256 hash of a text

Parameters
textThe text
Returns
The hash as uppercase hexadecimal text

◆ io.workpath()

string io.workpath ( string path)

Gets or sets the working directory, which relative paths (like "main.lua") start from

Parameters
pathNew working directory (optional)
Returns
The current working directory if path is omitted. Raises an error if the directory can't be set.