files = System.listDirectory "pathname"
-- files is a list of all files and subdirs in the pathname
local ndirs = 0
local nfiles = 0
for i = 1, table.getn(files) do
if files[i].directory then
ndirs = ndirs + 1
else
nfiles = nfiles + 1
end
end
print("# of subdirs found in the list", ndirs)
print("# of files found in the list", nfiles)
Warning: Don't run the script on Windows. The current version does not support System.listDirectory() yet.
Have fun!
Edited 9/26/2005 8:27PM
Last edited by KawaGeo on Tue Sep 27, 2005 1:30 pm, edited 2 times in total.
KawaGeo wrote:I haven't included some folders in the folder for testing but I believe they are counted as well.
No, they are not counted, listDirectory is the same like the DOS "dir" command or the Unix "ls" command (without any switches). But it is easy to count all files and directories in a directory and all subdirectories: