love.filesystem

Provides an interface to the user's filesystem.

This module provides access to files in two places, and two places only:

  • The root folder of the .love archive (or source directory)
  • The root folder of the game's save directory.

Each game is granted a single directory on the system where files can be saved through love.filesystem. This is the only directory where love.filesystem can write files. These directories will typically be found in something like:

  • Windows XP: C:\Documents and Settings\user\Application Data\LOVE\ or %appdata%\LOVE\
  • Windows Vista and 7: C:\Users\user\AppData\Roaming\LOVE or %appdata%\LOVE\
  • Linux: $XDG_DATA_HOME/love/ or ~/.local/share/love/
  • Mac: /Users/user/Library/Application Support/LOVE/

Files that are opened for write or append will always be created in the save directory. The same goes for other operations that involve writing to the filesystem, like mkdir.

Files that are opened for read will be looked for in the save directory, and then in the .love archive (in that order). So if a file with a certain filename (and path) exist in both the .love archive and the save folder, the one in the save directory takes precedence.

Note: All paths are relative to the .love archive and save directory. (except for the get*Directory() calls)

It is recommended to set your game's identity first in your conf.lua. You can set it with love.filesystem.setIdentity() as well.

Types

FileRepresents a file on the filesystem.
FileDataData representing the contents of a file.

Functions

love.filesystem.appendAppend data to an existing file.Added since 0.9.0
love.filesystem.createDirectoryCreates a directory.Added since 0.9.0
love.filesystem.enumerateReturns all the files and subdirectories in the directory. Removed in 0.9.0
love.filesystem.existsCheck whether a file or directory exists.
love.filesystem.getAppdataDirectoryReturns the application data directory (could be the same as getUserDirectory)
love.filesystem.getDirectoryItemsReturns all the files and subdirectories in the directory.Added since 0.9.0
love.filesystem.getIdentityGets the write directory name for your game.Added since 0.9.0
love.filesystem.getLastModifiedGets the last modification time of a file.Added since 0.7.1
love.filesystem.getSaveDirectoryGets the full path to the designated save directory.
love.filesystem.getSizeGets the size in bytes of a file.Added since 0.9.0
love.filesystem.getUserDirectoryReturns the path of the user's directory
love.filesystem.getWorkingDirectoryGets the current working directory.
love.filesystem.initInitializes love.filesystem, will be called internally, so should not be used explictly.
love.filesystem.isDirectoryCheck whether something is a directory.
love.filesystem.isFileCheck whether something is a file.
love.filesystem.isFusedGets whether the game is in fused mode or not.Added since 0.9.0
love.filesystem.linesIterate over the lines in a file.
love.filesystem.loadLoad a lua file (but not run it)
love.filesystem.mkdirCreates a directory. Removed in 0.9.0
love.filesystem.mountMounts a zip file or folder in the game's save directory for reading.Added since 0.9.0
love.filesystem.newFileCreates a new File object.
love.filesystem.newFileDataCreates a new FileData object.Added since 0.7.0
love.filesystem.readRead the contents of a file
love.filesystem.removeRemoves a file (or directory).
love.filesystem.setIdentitySets the write directory for your game.
love.filesystem.setSourceSets the source of the game, where the code is present.
love.filesystem.unmountUnmounts a zip file or folder previously mounted with love.filesystem.mount.Added since 0.9.0
love.filesystem.writeWrite data to a file.

Enums

FileDecoderHow to decode a given FileData.Added since 0.7.0
FileModeThe different modes you can open a File in.

See Also

Other Languages

Personal tools