List folders for edit some files inside that folders

Hi E's, I have a old project with about 10y, and in that time I do each page manually, the project was: http://rdsrc.us/fCIeXk, I don't use any dynamic language like php.
The problem is I have more than 100 folders, but I have the advanced that each folder have the same files, so is more easy edit the files inside them. The only thing I want to do to the files inside the folders was implement the code of google analytics, so I have to list each folder (maybe with a while), and edit the files I want in each folder.

For now I just want help to list all folder one by one, and in each while I edit the files inside the folder that I want.

How I list folder one by one?

The best regards, JC
LVL 4
Pedro ChagasWebmasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
This might be helpful to get you started:
http://php.net/manual/en/function.scandir.php

Read the "Directory Functions" that are listed in the left sidebar of that page.
ienaxxxCommented:
<?php
$dir = "/your/path/to/dir";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
        }
        closedir($dh);
    }
}
?> 

Open in new window

Pedro ChagasWebmasterAuthor Commented:
Hi @ienaxxx, I try to use your script (I just change the line 2 to $dir = "/"; because I put I same location of folders), but the only thing I receive is:
===============================
filename: .rnd : filetype: file filename: usr : filetype: dir filename: .. : filetype: dir filename: . : filetype: dir filename: .autofsck : filetype: file filename: home : filetype: dir filename: aquota.user : filetype: link filename: aquota.group : filetype: link filename: sbin : filetype: dir filename: etc : filetype: dir filename: .gnupg : filetype: dir filename: boot : filetype: dir filename: srv : filetype: dir filename: tmp : filetype: dir filename: var : filetype: dir filename: scripts : filetype: link filename: .autorelabel : filetype: file filename: opt : filetype: dir filename: lib : filetype: dir filename: sys : filetype: dir filename: mnt : filetype: dir filename: bin : filetype: dir filename: media : filetype: dir filename: dev : filetype: dir filename: root : filetype: dir filename: selinux : filetype: dir filename: .spamassassin : filetype: dir filename: .lesshst : filetype: file filename: proc : filetype: dir
==================================

Where is the problem?

The best Regards, JC
Ray PaseurCommented:
PHP has a predefined and context-aware constant DIRECTORY_SEPARATOR that should be used in place of the "/".  It is there because some operating systems do not use a slash as a directory separator.

You might want to learn about this function.  Hint: It is one of the "Directory Functions" that are listed in the left sidebar of that page I suggested you should read.
http://us3.php.net/manual/en/function.getcwd.php
Ray PaseurCommented:
This seems to be a place to start.
<?php // RAY_temp_joao.php
error_reporting(E_ALL);
echo "<pre>";

// WHAT DIRECTORY?
$dir = getcwd();

// READ THE CURRENT WORKING DIRECTORY
if (is_dir($dir))
{
    if ($dh = opendir($dir))
    {
        while (($file = readdir($dh)) !== false)
        {
            echo "filename: $file : filetype: " . filetype($dir . DIRECTORY_SEPARATOR . $file) . PHP_EOL;
        }
        closedir($dh);
    }
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.