Difference between revisions of "love.filesystem.enumerate"
m (1 revision: Importing from potato (again).) |
m |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{newinoldin|[[0.3.0]]|030|[[0.9.0]]|090|type=function|text=It has been renamed to [[love.filesystem.getDirectoryItems]]}} | ||
− | + | Returns a table with the names of files and subdirectories in the specified path. The table is not sorted in any way; the order is undefined. | |
− | + | If the path passed to the function exists in the game and the save directory, it will list the files and directories from both places. | |
== Function == | == Function == | ||
Line 12: | Line 13: | ||
{{param|string|dir|The directory.}} | {{param|string|dir|The directory.}} | ||
=== Returns === | === Returns === | ||
− | {{param|table|files| | + | {{param|table|files|A [[sequence]] with the names of all files and subdirectories as strings.}} |
== Examples == | == Examples == | ||
+ | === Simple Example === | ||
+ | <source lang="lua"> | ||
+ | local dir = "" | ||
+ | --assuming that our path is full of lovely files (it should at least contain main.lua in this case) | ||
+ | local files = love.filesystem.enumerate(dir) | ||
+ | for k, file in ipairs(files) do | ||
+ | print(k .. ". " .. file) --outputs something like "1. main.lua" | ||
+ | end | ||
+ | </source> | ||
=== Recursively find and display all files and folders in a folder and its subfolders. === | === Recursively find and display all files and folders in a folder and its subfolders. === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 44: | Line 54: | ||
* [[parent::love.filesystem]] | * [[parent::love.filesystem]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
− | {{#set:Description= | + | {{#set:Description=Returns all the files and subdirectories in the directory.}} |
− | }} | + | {{#set:Since=030}} |
+ | {{#set:PrettySince=0.3.0}} | ||
+ | {{#set:Removed=090}} | ||
+ | {{#set:PrettyRemoved=0.9.0}} | ||
+ | == Other Languages == | ||
+ | {{i18n|love.filesystem.enumerate}} |
Latest revision as of 02:44, 21 October 2022
Available since LÖVE 0.3.0 and removed in LÖVE 0.9.0 |
It has been renamed to love.filesystem.getDirectoryItems. |
Returns a table with the names of files and subdirectories in the specified path. The table is not sorted in any way; the order is undefined.
If the path passed to the function exists in the game and the save directory, it will list the files and directories from both places.
Contents
Function
Synopsis
files = love.filesystem.enumerate( dir )
Arguments
string dir
- The directory.
Returns
Examples
Simple Example
local dir = ""
--assuming that our path is full of lovely files (it should at least contain main.lua in this case)
local files = love.filesystem.enumerate(dir)
for k, file in ipairs(files) do
print(k .. ". " .. file) --outputs something like "1. main.lua"
end
Recursively find and display all files and folders in a folder and its subfolders.
function love.load()
filesString = recursiveEnumerate("", "")
end
-- This function will return a string filetree of all files
-- in the folder and files in all subfolders
function recursiveEnumerate(folder, fileTree)
local lfs = love.filesystem
local filesTable = lfs.enumerate(folder)
for i,v in ipairs(filesTable) do
local file = folder.."/"..v
if lfs.isFile(file) then
fileTree = fileTree.."\n"..file
elseif lfs.isDirectory(file) then
fileTree = fileTree.."\n"..file.." (DIR)"
fileTree = recursiveEnumerate(file, fileTree)
end
end
return fileTree
end
function love.draw()
love.graphics.print(filesString, 0, 0)
end
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