• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

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
0
Pedro Chagas
Asked:
Pedro Chagas
  • 3
3 Solutions
 
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.
0
 
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

0
 
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
0
 
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
0
 
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

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now