How not to count files in folder

Discussion in 'PHP' started by Kuna, May 7, 2010.

  1. #1
    This is my script which count file size in folder "files"
    But in folder "files" there is subfolder ''screenshot'', how to set up script not to count files in subfolder ''screenshot''

    <?php
    $maxupload=1024000000; // in byte
    $dir='files';
    $notcount=array('index.html','listing.php','descriptionfile.txt','ddimgtooltip.js','Thumbs.db');
    dirs($dir);
    $sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots];
    $_SESSION[tots]=array();
    unset($_SESSION[tots]);
    function dirs($dir){
    global $notcount;
    if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
     if ($file != "." && $file != "..") {
    if(is_dir($dir.'/'.$file)){
    dirs($dir.'/'.$file);
    }else{
    if (!in_array($file, $notcount)) {
    $fl=filesize($dir.'/'.$file);
    $_SESSION[tots]=$_SESSION[tots]+$fl;
    }
    }
    }
    }
    closedir($handle);
    }
    }
    ?>
    
    PHP:

     
    Last edited: May 7, 2010
    Kuna, May 7, 2010 IP
  2. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Like this?

    
    $pos = strpos($dir,"screenshot");
    
    if($pos === false) {
       $fl=filesize($dir.'/'.$file);
       $_SESSION[tots]=$_SESSION[tots]+$fl;
    }
    
    PHP:
     
    webrickco, May 7, 2010 IP
  3. Kuna

    Kuna Well-Known Member

    Messages:
    426
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    does anyone know how to integrate webricko's code into mine?
     
    Kuna, May 9, 2010 IP
  4. Qc4

    Qc4 Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Give this a try:

    <?php
    $maxupload=1024000000; // in byte
    $dir='files';
    $notcount=array('index.html','listing.php','descriptionfile.txt','ddimgtooltip.js','Thumbs.db');
    dirs($dir);
    $sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots];
    $_SESSION[tots]=array();
    unset($_SESSION[tots]);
    function dirs($dir){
    global $notcount;
    if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
     if ($file != "." && $file != "..") {
    if(is_dir($dir.'/'.$file)){
    if ($file != "screenshot") {
    dirs($dir.'/'.$file);
    }
    }else{
    if (!in_array($file, $notcount)) {
    $fl=filesize($dir.'/'.$file);
    $_SESSION[tots]=$_SESSION[tots]+$fl;
    }
    }
    }
    }
    closedir($handle);
    }
    }
    ?>
    
    PHP:
     
    Qc4, May 9, 2010 IP
  5. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #5
    use this:
    exec('ls /dir', $files);
    then loop through them and remove unnecessary entries
     
    gapz101, May 11, 2010 IP
  6. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Do it just like this:

    the strpos function will determine the position of "screenshot" text string into the analysed and and will only count when the path doesn't contain it.

    I expect the rest of the code was working just fine.

    
    <?php
    	$maxupload=1024000000; // in byte
    	$dir='files';
    	$notcount=array('index.html','listing.php','descriptionfile.txt','ddimgtooltip.js','Thumbs.db');
    	dirs($dir);
    	$sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots];
    	$_SESSION[tots]=array();
    	unset($_SESSION[tots]);
    
    	function dirs($dir){
    	global $notcount;
    		if ($handle = opendir($dir)) {
    			while (false !== ($file = readdir($handle))) {
    				if ($file != "." && $file != "..") {
    					if(is_dir($dir.'/'.$file)){
    						dirs($dir.'/'.$file);
    					}else{
    						if (!in_array($file, $notcount)) {
    
    							$pos = strpos($dir,"screenshot");
    
    							if($pos === false) {
    								$fl=filesize($dir.'/'.$file);
    								$_SESSION[tots]=$_SESSION[tots]+$fl;
    							}
    						}
    					}
    				}
    			}
    			closedir($handle);
    		}
    	}
    ?>
    
    PHP:
     
    webrickco, May 17, 2010 IP