antiblock
diamwall
  • Chatbox

    You don't have permission to chat.
    Load More
Sign in to follow this  
NewWars

[Function]Listdirectory

2 posts in this topic

Boas Pessoal.


 


Como ja não posto algo faz quase 1 mes se não mais, aqui vai algo simples mas util




function ListDirectory(dir, mask)
local files = {}
local tmpfile = '/tmp/'..pc.get_name()..'.ld'
os.execute('ls -1 '..dir..' > '..tmpfile)
local f = io.open(tmpfile)
if not f then return files end

local k = 1
for line in f:lines() do
if mask == "" or mask == nil then
files[k] = line
k = k + 1
elseif string.find(line,"%."..mask.."$") then
files[k] = line
k = k + 1
end
end

f:close()
return files
end


 


Como usar?



local files = ListDirectory('/usr/home/game/share/locale/germany/', "lua")
--DIRECTORICA, MASK
for i=1,table.getn(files) do
say(""..files[i])
end

Cumprimentos.


Share this post


Link to post
Share on other sites
antiblock
Cyphriun

 

Como ja não posto algo faz quase 1 mes se não mais, aqui vai algo simples mas util

 

Estás à vontade, posta quando quiseres.

Nós agradecemos.  :like:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this