Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter specific files

Status
Not open for further replies.

maverick

MIS
Apr 21, 1999
193
0
0
US
I want to list files in a dir but NOT *.php files
or *.htm files

here is what I have so far;
<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
}
closedir($handle);
?>

how do I filter *.php files ?

TIA

+--------------------------+
| "Hacker by Heart" |
| Yahoo! : saenzcorp |
+--------------------------+
 
Here's a function I either wrote or borrowed (and modified):
Code:
function get_dir_list($d,$fs)
{
	if ($dir = @opendir($d)) 
		{
		while (($file = readdir($dir)) !== false) 
			{
			if($file != ".." && $file != ".")
				{
				if (!(strpos($file,$fs) === false))
					$filelist[] = $file;
				}
			} 
		closedir($dir);
		}
	return($filelist);
}
The two parameters are:
$d: the directory
$fs: the file type you do want to include

I know this is not exactly you're looking for, but you should be able to modify it to meet your needs.

Ken
 
Thanks for your help !

here is what I did, but if this does not workout,
I will have a closer look at your code and see if I can make it work...

I added,
$self = basename($_SERVER['PHP_SELF']);
to make it identify itself

and then added,
$file != "$self"
to the if statement

Seems to work fine for now, but we'll see...

Thanks again !!!
;-D



+--------------------------+
| "Hacker by Heart" |
| Yahoo! : saenzcorp |
+--------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top