Solved

all the files in a directory php for windows

Posted on 2013-01-14
6
209 Views
Last Modified: 2013-01-15
php for windows

want to iterate through all the files in a directory

save into an array
foreach file, do something

I want to echo the contents of each file (but not with this question)
0
Comment
Question by:rgb192
6 Comments
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38777253
readdir() is the solution for you...

use readdir() to read the list of files and within while loop do the reading of each file and do whatever your scenario requires

http://php.net/manual/en/function.readdir.php
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 38777272
Like this:

<?php

$filesarray = array();

if ($handle = opendir('.')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != ".." && is_file($entry)) {
            //echo "$entry<br />";
            $filesarray[] = $entry;
        }
    }
    closedir($handle);
}

print_r($filesarray);
?>

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38777803
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:rgb192
ID: 38778548
<?php

$filesarray = array();

if ($handle = opendir('C:/gyb/')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != ".." && is_file($entry)) {
            echo "$entry<br />";
            $filesarray[] = $entry;
        }
    }
    closedir($handle);
}

print_r($filesarray);
?>

Open in new window




no output

I think because it says if
or
becuase I changed line 5 to add my windows directory in error
0
 

Author Closing Comment

by:rgb192
ID: 38778918
this answer works in the same directory

thanks
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 38780841
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to dynamically set the form action using jQuery.
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now