Skip to content

Instantly share code, notes, and snippets.

@jonpemby
Created March 6, 2018 02:14
Show Gist options
  • Save jonpemby/e781d534adc690900f20158b9fc383e9 to your computer and use it in GitHub Desktop.
Save jonpemby/e781d534adc690900f20158b9fc383e9 to your computer and use it in GitHub Desktop.
Lua scandir implementation
-- Lua implementation of PHP scandir function
-- special thanks to:
-- rhoster (https://stackoverflow.com/users/974053/rhoster)
-- ulmangt (https://stackoverflow.com/users/1212363/ulmangt)
function scandir(directory)
local i, t, popen = 0, {}, io.popen
local pfile = popen('ls -a "'..directory..'"')
for filename in pfile:lines() do
i = i + 1
t[i] = filename
end
pfile:close()
return t
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment