SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2010
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question exclude sub directory

    I want to list all files at directory and exclude sub directory (newfiles)

    i tried to use (if($file != "newfiles") )
    but no thing change

    foreach (ListFiles("/data") as $key=>$file){

    if($file != "newfiles"){
    $files=array_pop(explode('/',$file));
    $lfile[]=$files;
    }

    }

  2. #2
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you show us what is contained in the ListFiles() function? To debug, perhaps try adding an echo/print into your foreach() loop to see what $file is showing to gain a better idea.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2010
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function ListFiles($dir) {

        if(
    $dh opendir($dir)) {

            
    $files = Array();
            
    $inner_files = Array();

            while(
    $file readdir($dh)) {
                if(
    $file != "." && $file != ".." && $file[0] != '.') {
                    if(
    is_dir($dir "/" $file)) {
                        
    $inner_files ListFiles($dir "/" $file);
                        if(
    is_array($inner_files)) $files array_merge($files$inner_files);
                    } else {
                        
    array_push($files$dir "/" $file);
                    }
                }
            }

            
    closedir($dh);
            return 
    $files;
        }



Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •