Dont output directory's hidden files of my PC

Go4Expert Member
4Jul2011,15:29   #1
narekm's Avatar
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.
Skilled contributor
4Jul2011,19:19   #2
ManzZup's Avatar
i guess you can scan for something like the file attributes but it will slow down the process
Ambitious contributor
5Jul2011,04:42   #3
pein87's Avatar
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.