Detect files?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
soulphalanx
Posts: 35
Joined: Mon Aug 22, 2005 7:48 am

Detect files?

Post by soulphalanx »

Is there a way to find out how many files are in a folder and save it to a variable?
Durante
Posts: 65
Joined: Sun Oct 02, 2005 6:07 am
Location: Austria

Post by Durante »

Not very clean or efficient, but short:

Code: Select all

function System.numFiles(dir)
  -- - 2 to not count . and .. (remove if you want to count them)
  return table.getn(System.listDirectory(dir)) - 2
end
If you don't want to count subfolders as files you'll have to do a bit more work ;)
soulphalanx
Posts: 35
Joined: Mon Aug 22, 2005 7:48 am

Post by soulphalanx »

files = System.numFiles("/dir/dir/") , where "dir" is a directory, isnt working
Last edited by soulphalanx on Fri Nov 11, 2005 10:28 am, edited 1 time in total.
soulphalanx
Posts: 35
Joined: Mon Aug 22, 2005 7:48 am

Post by soulphalanx »

is there a more efficient method?
MagicianFB
Posts: 11
Joined: Mon Oct 10, 2005 8:45 am

Post by MagicianFB »

table.getn(System.listDirectory())

If you're not in the root directory you'll get to extra files.
Post Reply