Hello,
If you are using PHP5 then there is a function named
scandir[
^] This function can be used to first locate the newest folder in a path something like shown below.
$dirs = scandir('data', SCANDIR_SORT_DESCENDING);
$newest_dir = $dirs[0];
Once you locate the correct the folder then all you have to do is to count the number of files. WHich can be done using code similar to shown below
count(glob("/path/to/file/[!\.]*"));
Now if the count returned by above code is less than equal to max_allowed then you can copy the files in that folder else create a new folder first and copy the files in that newly created filter.
As far as boundary condition is concerned, you can keep copying the files to the latest folder found using
scandir
in a loop, till the count is <= the threshold. Once count reaches the threshold create a new folder and start copying to it.
Regards,