Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Read a Directory One Entry at a Time
How To Read a Directory One Entry at a Time? - PHP Script Tips - Working with Directoris and Files
✍: FYIcenter.com
If you want to read a directory one entry at a time, you can use opendir() to open the specified directory to create a directory handle, then use readdir() to read the directory contents through the directory handle one entry at a time. readdir() returns the current entry located by the directory pointer and moves the pointer to the next entry. When end of directory is reached, readdir() returns Boolean false. Here is a PHP script example on how to use opendir() and readdir():
<?php
mkdir("/temp/download");
$array["one"] = "Download PHP scripts at dev.fyicenter.com.\r\n";
$array["two"] = "Download Perl scripts at dev.fyicenter.com.\r\n";
$bytes = file_put_contents("/temp/download/todo.txt", $array);
print("List of files:\n");
$dir = opendir("/temp/download");
while ( ($file=readdir($dir)) !== false ) {
print("$file\n");
}
closedir($dir);
?>
This script will print:
List of files: . .. todo.txt
2007-04-23, 4978👍, 0💬
Popular Posts:
What is the purpose of the wait(), notify(), and notifyAll() methods? The wait(),notify(), and notif...
.NET INTERVIEW QUESTIONS - How can you avoid deadlock in threading? A good and careful planning can ...
What is the difference between "calloc(...)" and "malloc(...)"? 1. calloc(...) allocates a block of ...
What would you use to compare two String variables - the operator == or the method equals()? You can...
How To Enter Characters as HEX Numbers? - MySQL FAQs - Introduction to SQL Basics If you want to ent...