Difference between revisions of "love.filesystem.enumerate"
(Some more info about the order) |
|||
Line 1: | Line 1: | ||
− | + | Returns a table with the names of files and subdirectories in the directory in an undefined order. | |
Note that this directory is relative to the love folder/archive being run. Absolute paths will not work. | Note that this directory is relative to the love folder/archive being run. Absolute paths will not work. | ||
Line 11: | Line 11: | ||
{{param|string|dir|The directory.}} | {{param|string|dir|The directory.}} | ||
=== Returns === | === Returns === | ||
− | {{param|table|files| | + | {{param|table|files|A [[sequence]] with the name of all files and subdirectories as strings.}} |
== Examples == | == Examples == | ||
=== 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. === | ||
Line 43: | Line 43: | ||
* [[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=000}} | {{#set:Since=000}} | ||
== Other Languages == | == Other Languages == | ||
{{i18n|love.filesystem.enumerate}} | {{i18n|love.filesystem.enumerate}} |
Revision as of 21:07, 8 February 2012
Returns a table with the names of files and subdirectories in the directory in an undefined order.
Note that this directory is relative to the love folder/archive being run. Absolute paths will not work.
Contents
Function
Synopsis
files = love.filesystem.enumerate( dir )
Arguments
string dir
- The directory.
Returns
Examples
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