rewinddirSynopsis
Descriptionrewinddir() sets the resource pointer for a directory stream back to the start of the directory stream. One important note is that this function also causes the directory to be reread. You can use this feature to check for changes to a directory over the course of a script. See the example for details. ExampleExample 248. Loop through a directory until a set amount of time passes or the directory changes <?php $time_to_wait = 12; // For PHP3, use: $directory = '.'; $directory = getcwd (); $directory_stream = opendir ($directory); // Loop through the current entries in the directory while ($entry = readdir ($directory_stream)) { // Make an array that stores the filenames as keys and the file sizes as values $file[$entry] = filesize ($entry); } rewinddir ($directory_stream); print "Please wait $time_to_wait seconds until I am done with this example.<br> Do not modify the contents of $directory unless you want to see this script generate petty warnings.<br>"; for ($x=0; $x < $time_to_wait; ++$x) { // Display progress print "<br />\n" . round (($x/$time_to_wait) * 100) . "% done..."; // Make sure nothing has changed; complain loudly and die if it has while ($entry = readdir ($directory_stream)) { if (filesize($entry) != $file[$entry]) { die ("<br />Why did you have to go and change $entry? I was " . round (($x/$time_to_wait) * 100) . "% done..."); } } rewinddir ($directory_stream); // Sleep for one second. sleep (1); // Cause output to be displayed immediately, instead of being buffered. flush (); } print "<br />Thanks for waiting. You made this little script so happy!"; ?>
PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing
(Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch).
This material may be distributed only subject to the terms and conditions set forth
in the Open Publication License, v1.0 or later (the latest version is presently available at
http://www.opencontent.org/openpub/).
The authors of this book have elected not to choose any options under the OPL. This online book was obtained
from http://www.fooassociates.com/phpfer/
and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4
for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All
persons and entities shall have neither liability nor responsibility to any person or entity with respect to
any loss or damage arising from the information contained in this book.
|