Detecting success with network.download

You are wanting to get the size of all the files in the folder? Well that’s different than getting the file size of the directory.

Unix file systems directory size grows as more directory entries are added, but when the files are removed, the directory size does not go down, so it didn’t make much sense that you wanted the file size of the directory.

If you want the sum of the size of each file in the directory, then that’s different. You will have to loop over each file in the directory (which LFS can give you the list of files) and then get the stat information for each file and add it up.

Keep in mind too, that size may be in bytes, where as the OS may report it in 512byte blocks,
[import]uid: 199310 topic_id: 35385 reply_id: 143528[/import]

Hi Rob!

Thanks a lot!, I think your information is very useful!

I’m going to loop over each file in the directory and add it up.

Alberto. [import]uid: 44013 topic_id: 35385 reply_id: 143565[/import]

Hi,

Is there a way to get the size of a folder created in my DocumentsDirectory and where I download my files?

TIA

Alberto. [import]uid: 44013 topic_id: 35385 reply_id: 143300[/import]

You can use the LFS module to get the file sizes.

See this tutorial:

http://www.coronalabs.com/blog/2012/05/08/luafilesystem-lfs-tutorial/

[import]uid: 199310 topic_id: 35385 reply_id: 143395[/import]

Thanks Rob!

Following that examples, I tried this to get the size of a sub-folder:

local file\_path = system.pathForFile( "proba", system.DocumentsDirectory )  
  
local file\_attr = lfs.attributes( file\_path )  
local size = file\_attr.size  
  
print( "Sub-folder size: "..size )  
  

where “proba” is my sub-folder in DocumentsDirectory

I get 238 when the sub-folder’s size is 139 Kb
Do you know what am I doing wrong?
Is it possible to get directly the sub-folder’s size instead of adding the sizes of the files in the sub-folder? [import]uid: 44013 topic_id: 35385 reply_id: 143445[/import]

You are wanting to get the size of all the files in the folder? Well that’s different than getting the file size of the directory.

Unix file systems directory size grows as more directory entries are added, but when the files are removed, the directory size does not go down, so it didn’t make much sense that you wanted the file size of the directory.

If you want the sum of the size of each file in the directory, then that’s different. You will have to loop over each file in the directory (which LFS can give you the list of files) and then get the stat information for each file and add it up.

Keep in mind too, that size may be in bytes, where as the OS may report it in 512byte blocks,
[import]uid: 199310 topic_id: 35385 reply_id: 143528[/import]

Hi Rob!

Thanks a lot!, I think your information is very useful!

I’m going to loop over each file in the directory and add it up.

Alberto. [import]uid: 44013 topic_id: 35385 reply_id: 143565[/import]