Difference between revisions of "love.filesystem"
(Note about fused mode directory differences.) |
|||
(8 intermediate revisions by 6 users not shown) | |||
Line 15: | Line 15: | ||
! Notes | ! Notes | ||
|- | |- | ||
− | |Windows | + | |Windows |
− | |||
− | |||
− | |||
− | |||
− | |||
|<code>C:\Users\user\AppData\Roaming\LOVE</code> | |<code>C:\Users\user\AppData\Roaming\LOVE</code> | ||
|<code>%appdata%\LOVE\</code> | |<code>%appdata%\LOVE\</code> | ||
− | |When fused, save directory will created directly inside <code>AppData</code>, rather than as a sub-directory of <code>LOVE</code>. | + | |When fused, save directory will be created directly inside <code>AppData</code>, rather than as a sub-directory of <code>LOVE</code>. |
|- | |- | ||
− | | | + | |macOS |
|<code>/Users/user/Library/Application Support/LOVE/</code> | |<code>/Users/user/Library/Application Support/LOVE/</code> | ||
| - | | - | ||
Line 36: | Line 31: | ||
|- | |- | ||
|Android | |Android | ||
− | |||
|<code>/data/data/org.love2d.android/files/save/</code> | |<code>/data/data/org.love2d.android/files/save/</code> | ||
− | | | + | |<code>/sdcard/Android/data/org.love2d.android/files/save/</code> |
+ | |The alternative path is used when activating [[love.conf#externalstorage|t.externalstorage config]] option. Neither path is accessible through device directly due to Android restrictions. | ||
|} | |} | ||
− | 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 | + | 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 createDirectory. |
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. | 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. | ||
Line 49: | Line 44: | ||
It is recommended to set your game's identity first in your [[Config Files|conf.lua]]. You can set it with [[love.filesystem.setIdentity]] as well. | It is recommended to set your game's identity first in your [[Config Files|conf.lua]]. You can set it with [[love.filesystem.setIdentity]] as well. | ||
− | |||
== Types == | == Types == | ||
{{#ask: [[Category:Types]] [[parent::love.filesystem]] [[Concept:Current]] | {{#ask: [[Category:Types]] [[parent::love.filesystem]] [[Concept:Current]] | ||
Line 84: | Line 78: | ||
| ?PrettySince | | ?PrettySince | ||
| ?PrettyRemoved | | ?PrettyRemoved | ||
+ | | ?PrettyDeprecated | ||
}} | }} | ||
[[Category:Modules]] | [[Category:Modules]] | ||
{{#set:Description=Provides an interface to the user's filesystem.}} | {{#set:Description=Provides an interface to the user's filesystem.}} | ||
+ | |||
== See Also == | == See Also == | ||
* [[parent::love]] | * [[parent::love]] |
Latest revision as of 21:05, 19 November 2024
Provides an interface to the user's filesystem.
This module provides access to files in specific places:
- The root folder of the .love archive (or source directory)
- The root folder of the game's save directory.
- The folder containing the game's .love archive (or source directory), but only if specific conditions are met.
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:
OS | Path | Alternative | Notes |
---|---|---|---|
Windows | C:\Users\user\AppData\Roaming\LOVE
|
%appdata%\LOVE\
|
When fused, save directory will be created directly inside AppData , rather than as a sub-directory of LOVE .
|
macOS | /Users/user/Library/Application Support/LOVE/
|
- | - |
Linux | $XDG_DATA_HOME/love/
|
~/.local/share/love/
|
- |
Android | /data/data/org.love2d.android/files/save/
|
/sdcard/Android/data/org.love2d.android/files/save/
|
The alternative path is used when activating t.externalstorage config option. Neither path is accessible through device directly due to Android restrictions. |
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 createDirectory.
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.
Contents
Types
DroppedFile | Represents a file dropped from the window. | 0.10.0 | |
File | Represents a file on the filesystem. | ||
FileData | Data representing the contents of a file. |
Functions
love.filesystem.append | Append data to an existing file. | 0.9.0 | |
love.filesystem.areSymlinksEnabled | Gets whether love.filesystem follows symbolic links. | 0.9.2 | |
love.filesystem.createDirectory | Creates a directory. | 0.9.0 | |
love.filesystem.enumerate | Returns all the files and subdirectories in the directory. | 0.3.0 | 0.9.0 |
love.filesystem.exists | Check whether a file or directory exists. | 11.0 | |
love.filesystem.getAppdataDirectory | Returns the application data directory (could be the same as getUserDirectory) | ||
love.filesystem.getCRequirePath | Gets the filesystem paths that will be searched for c libraries when require is called. | 11.0 | |
love.filesystem.getDirectoryItems | Returns all the files and subdirectories in the directory. | 0.9.0 | |
love.filesystem.getIdentity | Gets the write directory name for your game. | 0.9.0 | |
love.filesystem.getInfo | Gets information about the specified file or directory. | 11.0 | |
love.filesystem.getLastModified | Gets the last modification time of a file. | 0.7.1 | 11.0 |
love.filesystem.getRealDirectory | Gets the absolute path of the directory containing a filepath. | 0.9.2 | |
love.filesystem.getRequirePath | Gets the filesystem paths that will be searched when require is called. | 0.10.0 | |
love.filesystem.getSaveDirectory | Gets the full path to the designated save directory. | 0.5.0 | |
love.filesystem.getSize | Gets the size in bytes of a file. | 0.9.0 | 11.0 |
love.filesystem.getSource | Returns the full path to the .love file or directory. | 0.9.0 | |
love.filesystem.getSourceBaseDirectory | Returns the full path to the directory containing the .love file. | 0.9.0 | |
love.filesystem.getUserDirectory | Returns the path of the user's directory | ||
love.filesystem.getWorkingDirectory | Gets the current working directory. | 0.5.0 | |
love.filesystem.init | Initializes love.filesystem, will be called internally, so should not be used explicitly. | ||
love.filesystem.isDirectory | Check whether something is a directory. | 11.0 | |
love.filesystem.isFile | Check whether something is a file. | 11.0 | |
love.filesystem.isFused | Gets whether the game is in fused mode or not. | 0.9.0 | |
love.filesystem.isSymlink | Gets whether a filepath is actually a symbolic link. | 0.9.2 | 11.0 |
love.filesystem.lines | Iterate over the lines in a file. | 0.5.0 | |
love.filesystem.load | Loads a Lua file (but does not run it). | 0.5.0 | |
love.filesystem.mkdir | Creates a directory. | 0.9.0 | |
love.filesystem.mount | Mounts a zip file or folder in the game's save directory for reading. | 0.9.0 | |
love.filesystem.newFile | Creates a new File object. | ||
love.filesystem.newFileData | Creates a new FileData object from a file on disk, or from a string in memory. | 0.7.0 | |
love.filesystem.read | Read the contents of a file. | ||
love.filesystem.remove | Removes a file (or directory). | ||
love.filesystem.setCRequirePath | Sets the filesystem paths that will be searched for c libraries when require is called. | 11.0 | |
love.filesystem.setIdentity | Sets the write directory for your game. | ||
love.filesystem.setRequirePath | Sets the filesystem paths that will be searched when require is called. | 0.10.0 | |
love.filesystem.setSource | Sets the source of the game, where the code is present. Used internally. | ||
love.filesystem.setSymlinksEnabled | Sets whether love.filesystem follows symbolic links. | 0.9.2 | |
love.filesystem.unmount | Unmounts a zip file or folder previously mounted with love.filesystem.mount. | 0.9.0 | |
love.filesystem.write | Write data to a file. |
Enums
FileDecoder | How to decode a given FileData. | 0.7.0 | 11.0 |
FileMode | The different modes you can open a File in. | ||
FileType | The type of a file. | 11.0 |
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info