| View previous topic :: View next topic |
| Author |
Message |
soulphalanx
Joined: 22 Aug 2005 Posts: 35
|
Posted: Thu Nov 10, 2005 9:19 am Post subject: Detect files? |
|
|
| Is there a way to find out how many files are in a folder and save it to a variable? |
|
| Back to top |
|
 |
Durante
Joined: 02 Oct 2005 Posts: 65 Location: Austria
|
Posted: Thu Nov 10, 2005 9:49 am Post subject: |
|
|
Not very clean or efficient, but short:
| Code: |
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 ;) |
|
| Back to top |
|
 |
soulphalanx
Joined: 22 Aug 2005 Posts: 35
|
Posted: Thu Nov 10, 2005 10:21 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
soulphalanx
Joined: 22 Aug 2005 Posts: 35
|
Posted: Fri Nov 11, 2005 10:27 am Post subject: |
|
|
| is there a more efficient method? |
|
| Back to top |
|
 |
MagicianFB
Joined: 10 Oct 2005 Posts: 11
|
Posted: Sat Nov 12, 2005 2:30 am Post subject: |
|
|
table.getn(System.listDirectory())
If you're not in the root directory you'll get to extra files. |
|
| Back to top |
|
 |
|