I tried Googling this and apparently I need some kind of a file system included.
Does anyone know an easy way to simply list all files in a given directory with as little modification as possible?
local file = io.popen("dir /B /A-D "..path, "r")
local file1 = file:read("*l")
local file2 = file:read("*l")
-- ... more files
if filen == nil then
-- no more files
file:close()
end
local tempname = os.tmpname()
os.execute("ls -p "..path.." | grep -v / > "..tempname)
local file = io.open(tempname, "r")
local file1 = file:read("*l")
local file2 = file:read("*l")
-- ... more files
if filen == nil then
-- no more files
file:close()
os.remove(tempname)
end
os.execute('rd /s/q "'..dir..'"')
function table.mergeValues(tbl, tbl2)
for k, v in pairs(tbl2) do
table.insert(tbl, v)
end
end
function io.isDirectory(path)
-- This can be removed if io.isdir gets updated
path = (path:sub(-1) == "/" or path:sub(-1) == "\\") and path:sub(1, -2) or path
return io.isdir(path)
end
function io.getPaths(directory)
local paths = {}
for file in io.enumdir(directory) do
if file ~= '.' and file ~= '..' then
path = directory..file
path = io.isDirectory(path) and path.."/" or path
table.insert(paths, path)
end
end
return paths
end
function io.getFilePaths(directory, deep)
local filePaths = {}
for _, path in pairs(io.getPaths(directory)) do
if deep and io.isDirectory(path) then
table.mergeValues(filePaths, io.getFilePaths(path, deep))
else
table.insert(filePaths, path)
end
end
return filePaths
end
function io.getDirectoryPaths(directory, deep)
local directoryPaths = {}
for _, path in pairs(io.getPaths(directory)) do
if io.isDirectory(path) then
table.insert(directoryPaths, path)
if deep then
table.mergeValues(directoryPaths, io.getDirectoryPaths(path, deep))
end
end
end
return directoryPaths
end
function dofileDirectory(directory, formats, deep)
for _, filePath in pairs(io.getFilePaths(directory, deep)) do
if type(formats) == "table" then
for _, format in pairs(formats) do
if filePath:sub(-4) == format then
dofile(filePath)
end
end
elseif filePath:sub(-4) == formats then
dofile(filePath)
end
end
end
local function getLocalPath()
local str = debug.getinfo(2, "S").source:sub(2)
return str:match("(.*/)")
end