Checking how many files in a folder ??? help
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Checking how many files in a folder ??? help

Started by NightLitch, 06 January, 2004, 21:41:18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NightLitch

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...
//NL

c h i l l a

look at this thread for getting  files in a folde

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 :)

tezlo

something like this would be a lot neater
pta? :)

c h i l l a

I agree totally...

but for now ??

I also was wishing once to execute c++ code through LUA.  but guess this will never happen

NightLitch

ThX Chilla & tezlo gonna check it out...
//NL

NightLitch

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
//NL

NightLitch

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
//NL

NightLitch

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
//NL

NightLitch

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...
//NL

c h i l l a

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.

NightLitch

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
//NL

c h i l l a

true I forgot one can get the size already by dir.

NightLitch

#12
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
//NL

SMF spam blocked by CleanTalk