Jump to content

Check for specific file type


Morten222

Recommended Posts

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

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.