Solved

echo filenames

Posted on 2013-06-12
5
301 Views
Last Modified: 2013-06-19
in windows want to interate through all the files in  a directory
that match file extension .php
and echo file name
0
Comment
Question by:rgb192
5 Comments
 
LVL 12

Accepted Solution

by:
adrian_brooks earned 167 total points
Comment Utility
Try something like this;

<?php
$dir_path = '\\path\\to\\directory';
if ($handle = opendir($dir_path)) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != ".." && preg_match('/\.php$/im', $entry)) {
            echo "$entry\n";
        }
    }
    closedir($handle);
}
?>

Open in new window


Have not tested this, but hope it helps.

~AB
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 167 total points
Comment Utility
<?php
 $dir = "*";
 foreach(glob($dir) as $file)  
 {  
if(pathinfo($file, PATHINFO_EXTENSION)=="php"){
 echo $file ."<br>";  
}
 }
 ?>

Open in new window

0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
Comment Utility
Have a look at scandir() and glob().  Both will return an array. You can use an iterator like foreach() to access each element of the array.
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Just to add, if you want a sub directory then amend
$dir = "*";
to
$dir = "mydir/*";
0
 

Author Closing Comment

by:rgb192
Comment Utility
these loop through the files

thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now