Dont output directory's hidden files of my PC

Discussion in 'PHP' started by narekm, Jul 4, 2011.

  1. narekm

    narekm New Member

    Joined:
    Mar 23, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Hello ...I just was trying to output the file names of different folders in my PC using PHP code...But I found that it outputs actually more than visible files in that particular folder..So what did I mean by visible that when I count the number of files in my folder it appears 18 but when i output it appears that the numer is 20. That two files are not visible. One if the is "Folder.jpg" and the second of them is a ".doc" file i opened and think it is inserted by "Administrator".....This is the code
    Code:
    <?php
    
     function getDirectoryList ($directory)  
      { 
    
    	// create an array to hold directory list 
    	$results = array(); 
    
    	// create a handler for the directory 
    	$handler = opendir($directory); 
    
    	// open directory and walk through the filenames 
    	while ($file = readdir($handler)) { 
    
    	  // if file isn't this directory or its parent, add it to the results 
    	  if ($file != "." && $file != "..") { 
    		$results[] = $file; 
    	  } 
    
    	} 
    
    	// tidy up: close the handler 
    	closedir($handler); 
    
    	// done! 
      return $results; 
    
      } 
      $array_1=getDirectoryList("C:\Documents and Settings\Администратор\Мои документы\Downloads"); 
    
      
     foreach($array_1 as $value) 
     { 
     echo "<br/>".$value; 
     }
    ?>
    So here is my question ...how can I output only that 18 files and not that invisible files ? Since I want to work only with files that I see.

    Please be gentle and help me.
     
  2. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    http://zontek.zzl.org
    i guess you can scan for something like the file attributes but it will slow down the process
     
  3. pein87

    pein87 Active Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    28
    Occupation:
    Web Dev
    Location:
    Limbo
    I don't think those resrictions are for php or the C file system functions. Those are just for the user.I personally don't know what can be done to stop this problem a side from reading some meta data from the file and seeing if that returns any data on its status. I think that stuff is stored in the registry and only certain files are hidden so you can't just declare a type. If you use this for a website though you could write a log file and then set certain files as hidden based on name or extension. If you do write a log make sure its in a json style so it can simply be included into the file.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice