PDA

View Full Version : Loading the amount of items in folder?



REEFˇ
August 29th, 2006, 04:37 PM
Lets say I specify a folder, "/Pictures" - is there anyway for flash to return a value of all the items (which will be only .jpgs) in this folder?

REEFˇ
August 29th, 2006, 07:44 PM
*BUMP*

I really need this & am willing to use PHP to return the value of the total number of items/jpgs in a given directory!

Jeff Wheeler
August 29th, 2006, 08:05 PM
Load some PHP like this,


<?php
$dir = '/root/dir/path/to/photos/';
$files = scandir($dir);
echo (count($files)-2);
?>

The `-2` is to remove `.` and `..`, which I assume you don't want.

REEFˇ
August 29th, 2006, 08:12 PM
Alright thats a start. I assume files is the variable that holds the numeric value of numbers within the directory?

And what do you mean it removes the `.` and `..`? All I need is a number, is there any reason dots would return as well?

Jeff Wheeler
August 29th, 2006, 08:16 PM
`scandir` returns an array of files and folders in the folder, which includes `.` referring to the current directory, and `..` referring to the parent directory (I'm pretty sure this is true on Windows, although I'm not positive). `count` will return the number of items in the array, and then we subtract two for the two pseudo-directories you don't want.

REEFˇ
August 29th, 2006, 08:18 PM
So count($files)-2 will return the number I'm looking for?

Jeff Wheeler
August 29th, 2006, 08:19 PM
It should…

Krilnon
August 29th, 2006, 08:23 PM
If you are doing what I think you are doing, you could try using a 'load until you can't load any more' approach like I suggested in this thread (http://www.kirupa.com/forum/showthread.php?t=230401).

Since you have access to PHP, though, I think PHP may be the better solution.

REEFˇ
August 29th, 2006, 08:37 PM
Does freewebs run PHP? I'm using freewebs to test the PHP and its not working :lol:.