note 119667 added to function.readdir

From: Date: Fri, 29 Jul 2016 18:03:14 +0000
Subject: note 119667 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-206127@lists.php.net to get a copy of this message
Find a file or folder within a directory. Say we want will loop n times by all subdirectories of a root directory and find a particular folder or file and know your address. In my case I needed to find each existing file in a directory metadata.opf a Calibre library and take all the data for each document this, if we consider that this directory had 20,000 folders author is a task that is humanly impossible . This recursive algorithm achieves do my homework. I hope it will help you. <?php $root = '../Classes'; $search_parameter = "CachedObjectStorageFactory.php"; //if we call the function spider as spider($root); //will show all the directory content including subdirectories //if we call the function spider as spider('../Classes', 'Shared'); //and will show the address of the directory spider($root, $search_parameter); closedir(); function spider($dir,$fileName=""){ $handle = opendir($dir); while($file= readdir($handle)){ if($file != "." && $file != ".."){ if($fileName=="") echo $dir."/".$file."<br>"; else if($file == $fileName) echo $dir."/".$file."<br>"; if(!is_file($dir."/".$file)) spider($dir."/".$file,$fileName); } } } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 152.206.71.75 ---- Manual Page -- http://php.net/manual/en/function.readdir.php Edit -- https://master.php.net/note/edit/119667 Del: integrated -- https://master.php.net/note/delete/119667/integrated Del: useless -- https://master.php.net/note/delete/119667/useless Del: bad code -- https://master.php.net/note/delete/119667/bad+code Del: spam -- https://master.php.net/note/delete/119667/spam Del: non-english -- https://master.php.net/note/delete/119667/non-english Del: in docs -- https://master.php.net/note/delete/119667/in+docs Del: other reasons-- https://master.php.net/note/delete/119667 Reject -- https://master.php.net/note/reject/119667 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206127) next »