PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Mon Jun 12, 2006 9:50 am
I am using following code for lising all files and folders in a specfic folder or directory.
Code: Select all
<?
function read_dir($dir) {
$array = array();
$d = dir($dir);
while (false !== ($entry = $d->read())) {
if($entry!='.' && $entry!='..') {
$entry = $dir.'/'.$entry;
if(is_dir($entry)) {
$array[] = $entry;
$array = array_merge($array, read_dir($entry));
} else {
$array[] = $entry;
}
}
}
$d->close();
return $array;
}
$abc = array();
$abc = read_dir("abc");
?>
i want to list folders and files in "abc" only, and then when i pass abc's child folder it should show me its files and folders.
how can i stop it when it has shown me foders and files in abc?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jun 12, 2006 11:41 am
remove the recursion.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Thu Jun 15, 2006 12:31 am
well, its done. but now the list is in aphabetical order, but i want to list all directories, but i want to list directories first and then files .
??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Jun 15, 2006 1:17 am
Store directories into an array, files in another. Sort each then combine them.