Morten222 Posted March 15, 2007 Share Posted March 15, 2007 Hello I have been making some code to check how many files I got in a folder. Now I was wondering if it is possible to check how many files of a specific type I got in the folder for example avi, jpg, 3gp and so on. Code so fare: $root='C:\Rot'; dirdig( $root , $count ) ; $filer = $count['files']; echo $filer function dirdig( $dir , &$count ){ $ssss = glob( $dir.'/*' ) ; if( !empty( $ssss ) ){ foreach( $ssss as $y ){ if( is_dir( $y ) ){ $count['dirs']++ ; dirdig( $y , $count ) ; } if( is_file( $y ) ){ $count['files']++ ; } } } } Link to comment https://forums.phpfreaks.com/topic/42872-check-for-specific-file-type/ Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 pathinfo() or path_info() via php.net will help. Link to comment https://forums.phpfreaks.com/topic/42872-check-for-specific-file-type/#findComment-208209 Share on other sites More sharing options...
Morten222 Posted March 16, 2007 Author Share Posted March 16, 2007 Have been reading all about pathinfo() but i still can't figure it out ??? Could you give me a littel hint? Link to comment https://forums.phpfreaks.com/topic/42872-check-for-specific-file-type/#findComment-208673 Share on other sites More sharing options...
skali Posted March 16, 2007 Share Posted March 16, 2007 <?php $root='C:\\test\\'; function dirdig( $dir , &$count ){ $ssss = glob( $dir.'/*' ) ; if( !empty( $ssss ) ){ foreach( $ssss as $y ){ if( is_dir( $y ) ){ $count['dirs']++ ; dirdig( $y , $count ) ; } if( is_file( $y ) ){ $count['files']++ ; $file = explode('.',$y); switch ($file[1]){ case 'mp3': $mp3++; break; case 'txt': $txt++; break; } } } } } dirdig( $root , $count ) ; $filer = $count['files']; ?> Hope this can help. Link to comment https://forums.phpfreaks.com/topic/42872-check-for-specific-file-type/#findComment-208674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.