Difference between revisions of "love.filesystem.enumerate"

m (1 revision: Imported docs from potato.)
Line 1: Line 1:
  
 +
Return all the files and subdirectories in the directory.
 +
 +
Note that this directory is relative to the love folder/archive being run. Absolute paths will not work.
  
 
== Function ==
 
== Function ==
Line 41: Line 44:
 
* [[parent::love.filesystem]]
 
* [[parent::love.filesystem]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=}}
+
{{#set:Description=Return all the files and subdirectories in the directory.
 +
}}

Revision as of 16:17, 14 February 2010

Return all the files and subdirectories in the directory.

Note that this directory is relative to the love folder/archive being run. Absolute paths will not work.

Function

Synopsis

files = love.filesystem.enumerate( dir )

Arguments

string dir
The directory.

Returns

table files
The files/subdirectories in the directory

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