0

I want to get number of video files in a folder suppose .mp4,.mp3,.flv..etc extension and exclude files like .webm extension.How to do this with php condeigniter?

A Sahra
  • 118
  • 1
  • 12
  • 1
    You can use directory helper for count files with relevant files format, please find here https://www.codeigniter.com/userguide3/helpers/directory_helper.html – Anish Agarwal Dec 10 '16 at 06:53
  • @AnishAgarwal in directory helper there are three function available $source_dir,$directory_depth,$hidden i find nothing more on counting files and excluding some – A Sahra Dec 10 '16 at 07:01
  • it will return you all files which directory contains, then you can count of your formatted files, or you can check relevant solution here http://stackoverflow.com/questions/14194173/count-number-of-files-in-folder-in-php – Anish Agarwal Dec 10 '16 at 07:45
  • @AnishAgarwal !! How to check for files that are duplicate in names but not extension,means there are files with same name but different extension? – A Sahra Dec 14 '16 at 05:24
  • @A Sahra, Here we can compare files with extensions. Because in a single directory, two files couldn't be with the same name and same extension. – Anish Agarwal Dec 14 '16 at 06:49
  • In my situation i have two file with same name and different extension how to escape duplication between these two. – A Sahra Dec 14 '16 at 09:53

1 Answers1

0

Write a custom function like this

function getCount(){
$overAllCount = 0;
$directory = base_url().'uploads';
$mp4count = glob($directory . '*.mp4');
$mp3count = glob($directory . '*.mp3');
$flvcount = glob($directory . '*.flv');

if ( $mp4count !== false )
{
    $filecount = count( $mp4count );
    $overAllCount += $filecount;
}
if ( $flvcount !== false )
{
    $filecount = count( $flvcount );
    $overAllCount += $filecount;
}
if ( $mp3count!== false )
{
    $filecount = count( $mp3count);
    $overAllCount += $filecount;
}
return $overAllCount;
}
Rajesh
  • 934
  • 12
  • 23
  • I was looking for a shorter code something like count(* formats,except this format(webm)) – A Sahra Dec 12 '16 at 07:56
  • 1
    Got you. But, when you make it in Utility or Common files, this would become the shorter code as you are looking for. Or, since the glob is taking the pattern, you can pass the reuglar expression patterns too to get at once. When I find time I will try to give that pattern later. – Rajesh Dec 12 '16 at 08:07
  • !! How to check for files that are duplicate in names but not extension,means there are files with same name but different extension? – A Sahra Dec 14 '16 at 05:25
  • since glob returns array, you can combine all array output to a single array and then iterate that array to check the count (you will have to explode the file name by dot so that you can consider first element of each array item) – Rajesh Dec 14 '16 at 09:44