Jump to content




Getting file size of current program?


  • You cannot reply to this topic
3 replies to this topic

#1 RadiationAlert

  • Members
  • 17 posts

Posted 07 June 2015 - 04:28 PM

I'm running a program that calculates the amount of disk space used (not free). I get an error whenever the loop iterates over the file actually calculating:

test:9: No such file

local Disk = shell.dir ();
local DiskContents = fs.list (Disk);

local DiskSize = 0

for index, file in pairs (DiskContents) do
print ("Previous Space Calculated: "..DiskSize);
print ("Current File: "..file);
***** DiskSize = DiskSize + fs.getSize (file); ***** Line 9
end

print ("Total Disk Space Used: "..DiskSize.." of "..fs.getFreeSpace (Disk));


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 June 2015 - 04:39 PM

That's because you aren't using the full path.

Your code lists things in the directory "Disk", eg.
Disk/startup
Disk/program
Disk/help

But fs.list returns a table of names looking like this:
startup
program
help

fs.getSize expects to get the full path (Disk/startup), but is handed the "local" path (startup).

fs.combine( "Disk", "file" ) will return "Disk/file", or the absoulte path. (Note: you should still pass it the variable file, not "file". The string was an example)

#3 RadiationAlert

  • Members
  • 17 posts

Posted 07 June 2015 - 04:44 PM

By converting to the full path, it seems to work correctly now. Thanks.

#4 davidgumazon

  • Members
  • 30 posts
  • LocationPhilippines

Posted 20 July 2015 - 10:33 AM

View PostRadiationAlert, on 07 June 2015 - 04:28 PM, said:

local Disk = shell.dir ();
local DiskContents = fs.list (Disk);

local DiskSize = 0

for index, file in pairs (DiskContents) do
print ("Previous Space Calculated: "..DiskSize);
print ("Current File: "..file);
***** DiskSize = DiskSize + fs.getSize (file); ***** Line 9
end

wow! i learn new code in LUA i finally get it how for index, var in pairs(val) do end it works :D thank you for the Code T_T
-- i test this code and it works :D/>
test={'xxd','xdx','xdd'}
for var1, var2 in pairs(test) do
if var2=='xdd' then
  print(var1) print(var2)
end
end
+1 Like

This Code for my OS ;D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users