@@ -601,26 +601,25 @@ public function getFileStructure($main_path, $iterator_result, $is_root_dir)
601601 return $ iterator_result ;
602602 }
603603
604- try {
605- $ it = new \FilesystemIterator (
606- $ main_path ,
607- \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::KEY_AS_FILENAME
608- );
604+ if ( ! is_readable ($ main_path ) ) {
605+ return $ iterator_result ;
606+ }
609607
610- if (!$ is_root_dir ) {
611- $ iterator_last_dir_offset = 0 ;
608+ try {
609+ $ scan = @scandir ($ main_path , SCANDIR_SORT_NONE );
610+ if ( $ scan === false ) {
611+ return $ iterator_result ;
612612 }
613+ sort ($ scan , SORT_STRING );
613614
614- foreach ( $ it as $ file_name => $ path ) {
615- if ( ! $ path ) {
616- continue ;
617- }
615+ $ iterator_last_dir_offset = 0 ;
618616
619- if ( $ file_name === ".. " || $ file_name === ". " ) {
617+ foreach ( $ scan as $ file_name ) {
618+ if ( $ file_name === '.. ' || $ file_name === '. ' ) {
620619 continue ;
621620 }
622621
623- $ path = ( string ) $ path ;
622+ $ path = $ main_path . DIRECTORY_SEPARATOR . $ file_name ;
624623
625624 if ( is_file ($ path ) && !is_link ($ path ) ) {
626625 // Extensions filter
@@ -658,21 +657,19 @@ public function getFileStructure($main_path, $iterator_result, $is_root_dir)
658657
659658 $ this ->output_counter_files ++;
660659
661- // Skip if start is not reached for inner last dir
662- if ( !$ is_root_dir ) {
663- $ iterator_last_dir_offset ++;
664- if ( $ it ->getPath () === $ this ->last_dir_on_exit && $ iterator_last_dir_offset - 1 < $ this ->output_files_offset ) {
665- continue ;
666- }
660+ // Resume in this directory (root or subdir): skip first on_exit_dir_offset matching files.
661+ $ iterator_last_dir_offset ++;
662+ if ( $ main_path === $ this ->last_dir_on_exit && $ iterator_last_dir_offset - 1 < $ this ->output_files_offset ) {
663+ continue ;
667664 }
668665
669666 $ this ->output_files []['path ' ] = $ path ;
670667
671668 // Return if file limit is reached
672669 if ($ this ->output_counter_files >= $ this ->output_files_maximum ) {
673670 $ iterator_result ->max_files_interrupt = true ;
674- $ iterator_result ->on_exit_dir_path = $ it -> getPath () ;
675- $ iterator_result ->on_exit_dir_offset = isset ( $ iterator_last_dir_offset) ? $ iterator_last_dir_offset : 0 ;
671+ $ iterator_result ->on_exit_dir_path = $ main_path ;
672+ $ iterator_result ->on_exit_dir_offset = $ iterator_last_dir_offset ;
676673 return $ iterator_result ;
677674 }
678675 } elseif ( is_dir ($ path ) && !is_link ($ path ) ) {
0 commit comments