Hello developer friends,
i have a task that described as my question subject. in my case, the directory structure is deep enough and this is the directory sample:
D:\DATA\PROGRAM 11\AREA 01\CAB 001\JS 0100 INSIGHT\2008\01 JANUARY\01 i have to find image files inside each last child directory. I have to find files with the help from some parameters, some parameter are string that contain in file_name, and some parameter to help system match directory name then searching method can be more accurately. My code still not complete and take long time to complete, it's about 4-5 minutes. please see my code below,
<?php function readdirScandir($dir, $extension) { $files = array(); $root = @scandir($dir, SCANDIR_SORT_NONE); foreach($root as $entry) { if($entry === '.' || $entry === '..') continue; $fullpath = $dir.'/'.$entry; if(is_file($fullpath)) { if (0 === strcasecmp($extension, pathinfo($fullpath, PATHINFO_EXTENSION))) $files[] = $fullpath; continue; } foreach(readdirScandir($fullpath, $extension) as $entry) { if(0 === strcasecmp($extension, pathinfo($entry, PATHINFO_EXTENSION))) { $files[] = $entry; } } } return $files; } $root_dir = getcwd(); //place this before any script you want to calculate time $time_start = microtime(true); // include subdirectories $dirlist = readdirScandir($root_dir, 'tif'); var_dump($dirlist); $time_end = microtime(true); //dividing with 60 will give the execution time in minutes other wise seconds $execution_time = ($time_end - $time_start)/60; //execution time of the script echo '<br><b>Total Execution Time:</b> '.$execution_time.' Mins'; ?> I would appreciate every advice and your help. Thanks in advance and nice weekend.