Hey Guys. Wonder; Is there possible to get the size
of all files stored in a folder and maybe building a table
to view the files ??? (the file-names)
help plz...
look at this thread for getting files in a folde
http://board.univ-angers.fr/thread.php?threadid=463&boardid=11&sid=9bc96aadc611158f25eb6c0a22b72e2d (http://board.univ-angers.fr/thread.php?threadid=463&boardid=11&sid=9bc96aadc611158f25eb6c0a22b72e2d)
the check your lua manual for seek.
then mix it together, and build a table :)
something like this (http://lua-users.org/wiki/PitLibDirectoryStuff) would be a lot neater
pta? :)
I agree totally...
but for now ??
I also was wishing once to execute c++ code through LUA. but guess this will never happen
ThX Chilla & tezlo gonna check it out...
Guys one thing now...
can I use this function I got from Plop and get the filesize:
function GetFileSize(file)
_INPUT = readfrom(file)
size = format("%0.2f", (seek(_INPUT, "end")/1024))
readfrom()
return size
end
or what should I do
one other thing how do I do this:
file+file+file = togheter value in KB then...
how do the function look like...
or can I just add them together like that, ex:
local TOTALFILESIZE = file1.txt+file2.txt
and then execute above function getfilesize
is this function right... I multiplie Userfile x i=total users
hope you get my expaination...
this is what i have created so far...
function ShowReds(curUser,data)
execute("dir userinfo/a-d /b > Database.dat")
LoadsTable(TEST,"Database.dat")
local temp = {}
for Nicks, num in TEST do
tinsert(temp, Nicks)
end
sort(temp)
for i=1,getn(temp) do
local _,_,vNicks = strfind(temp[i],"(%S+)")
-- curUser:SendData(BotName,""..i..". Nicks: "..vNicks..", Size on file "..GetFileSize("userinfo/"..vNicks..".log"))
local TotalValue =GetFileSize("userinfo/"..vNicks..".log") * i
curUser:SendData(BotName,"Total Size on Userinfo: "..TotalValue.." KB")
end
end
I have huge problems this should be so easy but I just don't
get it working...
from above code how do I get it to show just ONE line
not all lines the end Line gives the value I want...
but don't want to show all others.. how would I do...
plz help...
I would do it like the manual does it.. not different,
you get the filename of the folder in your file from the execute.
then readout the file.
and open each file, and seek its filehandle,
seek will return a number when filehandle is given, and the insert that number in a table.
this is it Plop:
function ShowReds(curUser,data)
PATH = "d:/!?PtokaX Stuff Folder?!/!-Current Hub-!/"
execute("dir \""..PATH.."/scripts/userinfo\" %1 /-p /o:gn > \""..PATH.."/scripts/Listinglogs.lst\"")
FILE = "Listinglogs.lst"
TEST = {}
Load(TEST,FILE)
for a,b in TEST do
curUser:SendData(BotName, "A: "..a.." B:"..b)
end
end
function Load(table,file)
local handle = openfile(file, "r")
if (handle) then
local line = read(handle)
while line do
local _,_,size,name = strfind(line, "%s(%S+)%s(%S+.log)$")
table[name]=size
line = read(handle)
end
closefile(handle)
end
end
true I forgot one can get the size already by dir.
just so you can see how I done it.. with Plop's help...
function GetFile()
execute("dir \""..HubSoftFolder.."/scripts/userinfo\" %1 /-p /o:gn > \""..HubSoftFolder.."/scripts/log/FileLog.dat\"")
tFile = sLogPath.."FileLog.dat"
Temp = {}
Load(Temp,tFile)
for a, b in Temp do
iSize = b + GetFileSize(sInfoPath..""..a)
end
return iSize
end
function GetFileSize(file)
_INPUT = readfrom(file)
size = format("%0.2f", (seek(_INPUT, "end")/1024))
readfrom()
return size
end
function Load(table,file)
local handle = openfile(file, "r")
if (handle) then
local line = read(handle)
while line do
local _,_,size,name = strfind(line, "%s(%S+)%s(%S+.log)$")
if size and name then
table[name]=size
end
line = read(handle)
end
closefile(handle)
end
end