Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] dir list filtering extensions


[SOLVED] dir list filtering extensions

Reply
  #1 (permalink)  
Old 02-22-06, 05:42 PM
id10tn00b's Avatar
id10tn00b id10tn00b is offline
Newbie Coder
 
Join Date: Oct 2004
Location: new mexico
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] dir list filtering extensions

i tried to make the subject as simple and to the point as possible. heres my deal...

i have a chunk of code that reads a folder...

$dir = dir("$dir_games");
while ($file = $dir->read()) {
if (!is_dir("$file") && ($file != ".htaccess")) {
$filelist[] = $file;
}

for one, the part about !isdir doesnt work, if i have a dir in the current dir, it still shows up in the list. but it works for the . and .. so im not sure whats wrong there but thats not my issue im trying to fix.

what im looking to be able to do is (and it will actually fix my other problem by default) is to make the dir read only list items with a .swf extension. so a data file wont show up in the list. im not sure the best way to go about doing that.

i saw on my searches how to create a function to use $case and separate the files based on extension, but im basically reading the files i need into a $variable[$count] with $count ++ on each file to add to the list, but i only want it to read the .swf files, not anything else in the folder.

if its easy enough, i could use a small command to add in or if its something that requires some retooling of my code, any links to a resource would help a lot.

thanks
__________________
http://www.yougetalife.com
i <?php therefore $i == am;
http://www.coredumpcomputerservice.com
Reply With Quote
  #2 (permalink)  
Old 02-22-06, 07:48 PM
ben.periton ben.periton is offline
Wannabe Coder
 
Join Date: Oct 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
Just check that the last 3 letters are swf and add to $filelist.

PHP Code:

$dir dir($dir_games);

while (
$file $dir->read()) {
    if (
substr($file,-3,3) == 'swf') {
        
$filelist[] = $file;
    }

__________________
Ben Periton
http://ben.periton.co.uk
Reply With Quote
  #3 (permalink)  
Old 02-22-06, 08:38 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
This function is another nice tool.

http://www.php.net/manual/en/function.fnmatch.php
Reply With Quote
  #4 (permalink)  
Old 02-22-06, 09:38 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
Try this:
http://www.php.net/glob

PHP Code:

<?php


$files 
glob("folder_name/*.swf"); // only returns files with .swf extension

foreach ($files as $filename)
echo 
"$filename size: " filesize($filename) . " bytes<br />\n"// do whatever

?>

Last edited by Keith; 02-22-06 at 09:41 PM.
Reply With Quote
  #5 (permalink)  
Old 08-06-08, 12:01 AM
id10tn00b's Avatar
id10tn00b id10tn00b is offline
Newbie Coder
 
Join Date: Oct 2004
Location: new mexico
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Trophee [solved] dir list filtering extensions

i know its been a while since i checked here, but i got sidetracked on other projects. those ideas look good, i think i will try these and see which one i like best.

thanks!
__________________
http://www.yougetalife.com
i <?php therefore $i == am;
http://www.coredumpcomputerservice.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 06:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.