PtokaX forum

Development Section => Your Developing Problems => Topic started by: NightLitch on 06 January, 2004, 21:41:18

Title: Checking how many files in a folder ??? help
Post by: NightLitch on 06 January, 2004, 21:41:18
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...
Title:
Post by: c h i l l a on 06 January, 2004, 21:50:23
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 :)
Title:
Post by: tezlo on 06 January, 2004, 22:15:59
something like this (http://lua-users.org/wiki/PitLibDirectoryStuff) would be a lot neater
pta? :)
Title:
Post by: c h i l l a on 06 January, 2004, 22:18:55
I agree totally...

but for now ??

I also was wishing once to execute c++ code through LUA.  but guess this will never happen
Title:
Post by: NightLitch on 06 January, 2004, 22:20:18
ThX Chilla & tezlo gonna check it out...
Title:
Post by: NightLitch on 06 January, 2004, 23:03:17
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
Title:
Post by: NightLitch on 06 January, 2004, 23:06:18
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
Title:
Post by: NightLitch on 06 January, 2004, 23:57:56
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
Title:
Post by: NightLitch on 07 January, 2004, 01:02:03
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...
Title:
Post by: c h i l l a on 07 January, 2004, 01:02:34
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.
Title:
Post by: NightLitch on 07 January, 2004, 17:40:05
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
Title:
Post by: c h i l l a on 07 January, 2004, 19:00:30
true I forgot one can get the size already by dir.
Title:
Post by: NightLitch on 07 January, 2004, 19:11:28
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