On Tue, Jan 26, 2010 at 2:06 PM, Nathan Nobbe <quickshiftin@xxxxxxxxx>wrote: > On Tue, Jan 26, 2010 at 2:05 PM, Christoph Boget <cboget@xxxxxxxxxxx>wrote: > >> I executed the following test script several times. Each time, in a >> separate terminal window, I ran "touch bob.txt" after the script started >> echoing out. After the script completed, I deleted bob.txt. During each >> execution, not once did bob.txt show up in the output. This makes me >> believe that the file collection that DirectoryIterator is going to work >> with is set at instantiation. If that's the case, it makes little sense >> to >> me that you are unable to get the size of that collection from the >> DirectoryInterator object. >> >> <?php >> $dirList = new DirectoryIterator(MY_DIR); >> foreach($dirList as $file ) >> { >> echo $file->getFilename() . '<br>'; >> flush(); >> sleep( 1 ); >> } >> ?> >> > > in that case you would likely need to expose something extra from the C > layer. > fwiw.., a quick peak at the code reveals the following: . in the DirectoryIterator constructor it looks like the directory is iterated at the C level /* {{{ proto void DirectoryIterator::__construct(string path) Cronstructs a new dir iterator from a path. */ SPL_METHOD(DirectoryIterator, __construct) { /* .... */ spl_filesystem_dir_open(intern, path TSRMLS_CC); /* .... */ } /* }}} */ . this iteration is implemented in some php stream code, but it looks like some internal C structures are tracking the file count PHPAPI int _php_stream_scandir(char *dirname, char **namelist[], int flags, php_stream_context *context, int (*compare) (const char **a, const char **b) TSRMLS_DC) { /* im pretty sure this is where the number of files is stored .. */ int nfiles = 0; /* read rest of function in main/streams/streams.c */ } -nathan