Reading directory and file names 
Author Message
 Reading directory and file names

Could someone point me in the direction of the manual page that deals
with how I woul ddo the following:

I have a series of directories.  The Top level is "photos" and each
directory under that is "vacation", "home", "baby", etc.  Each of the
directories has jpg files in them.

How can I read all the directories and file names so I can dynamically
and automatically set up links to everything in those directories no
matter how often their contents change?

--

http://www.*-*-*.com/

To email me, remove "Sugapablo-" from the email address



Wed, 27 Apr 2005 03:34:11 GMT  
 Reading directory and file names
In a fit of e{*filter*}ment on Fri, 08 Nov 2002 14:34:11 -0500, Sugapablo

| Could someone point me in the direction of the manual page that deals
| with how I woul ddo the following:
|
| I have a series of directories.  The Top level is "photos" and each
| directory under that is "vacation", "home", "baby", etc.  Each of the
| directories has jpg files in them.
|
| How can I read all the directories and file names so I can dynamically
| and automatically set up links to everything in those directories no
| matter how often their contents change?

Check php.net for the following functions:

opendir()
readdir()
is_dir()
closedir()

The following was _old_ code I used for a dynamic MP3 Intranet site..
but from php.net and the code below, you should get an understanding as
to how it works =)

Please also be aware that this is a snip of code from a complete HTML
file, and some HTML formatting in the code will be defined previous.

The code reads from a dir on drive C: and its subdirectories (they were
defined within genre named subdirs) and from one location on drive D:.

The HTML was part of a table that used the subdir names (rock, ambient,
commercial, etc) and used those dir names as genre headings for the
generated HTML page. You could use the same method reading 'vacation',
'home' etc as the headings, or navigation links to there relative page
as an example.

<?
                                $mp3_ctr = 0;
                                $mp3_coll_bytes = 0;

                                $handle = opendir('c:/wwwdata/mp3/files/');
                                        while (($file = readdir($handle)) !== false) {
                                                if (!is_dir($file)) {
                                        $directory = "c:/wwwdata/mp3/files/".$file;
                                                        $mp3_dir = split('/', $directory);
                                                        $style = $mp3_dir[4];
                                                        $style = str_replace('_', ' ', $style);
                                                        $style = ucwords($style);

                                                        echo "<tr>\n<td align=center bgcolor=#222255
colspan=2>\n<b>".$style."</b>\n</td>\n</tr>\n<tr>\n<td align=left
bgcolor=#111144 colspan=2>\n";

                                                $sub_dir = opendir($directory);
                                                                while (($file = readdir($sub_dir)) !== false) {
                                                                        if (!is_dir($file) && strstr($file, '.mp3')) {
                                                                                $mp3_ctr +=1;
                                                                                //$mp3_coll_bytes = filesize($file);

                                                                                $two = split('mp3', $directory);

                                                                                $display_name = str_replace('_', ' ', $file);
                                                                                if (strstr($display_name, '--')) {
                                                                                        $display_name = str_replace('--', ' -- ',
$display_name);
                                                                                }
                                                                                $display_name = ucwords($display_name);

                                                                                /* echo "<a href=\"" . '/mp3' . $two[1] . "/" .
$file . "\">" . $display_name . "</a><br>\n"; */
                                                                                echo $display_name . "<br>\n";
                                                                        }
                                                                }
                                                        closedir($sub_dir);
                                                        echo "</td>\n</tr>\n";
                                }
                                        }
                                closedir($handle);

                                echo "<tr>\n<td align=center bgcolor=#222255
colspan=2>\n<b>[Total K]</b>\n</td>\n</tr>\n<tr>\n<td align=left
bgcolor=#111144 colspan=2>\n";

                                $handle = opendir('d:/mp3/own');
                                        while (($file = readdir($handle)) !== false) {
                                                if (!is_dir($file) && strstr($file, '.mp3')) {
                                                        $mp3_ctr +=1;

                                                        $display_name = str_replace('_', ' ', $file);
                                                        if (strstr($display_name, '--')) {
                                                                $display_name = str_replace('--', ' -- ',
$display_name);
                                                        }
                                                        $display_name = ucwords($display_name);

                                                        /* echo "<a href=\"/ch00ns/" . $file . "\">" .
$display_name . "</a><br>\n"; */
                                                        echo $display_name . "<br>\n";
                                                }
                                        }
                                closedir($handle);
                        ?>
--
+--------------------------+
|     digiServ Network     |
|      Web solutions       |
| http://www.*-*-*.com/ |
+--------------------------+

  Remove WINDOZE to reply



Wed, 27 Apr 2005 04:59:50 GMT  
 Reading directory and file names


Quote:

> Could someone point me in the direction of the manual page that deals
> with how I woul ddo the following:

> I have a series of directories.  The Top level is "photos" and each
> directory under that is "vacation", "home", "baby", etc.  Each of the
> directories has jpg files in them.

> How can I read all the directories and file names so I can dynamically
> and automatically set up links to everything in those directories no
> matter how often their contents change?

http://www.php.net/manual/en/ref.dir.php
http://www.php.net/manual/en/class.dir.php
http://www.php.net/manual/en/function.readdir.php

Cheers,
NC



Wed, 27 Apr 2005 10:25:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Making file path control only select directory paths not file names

2. Reading name of actual directory

3. DOS File Lookup - just the file name, not the path AND file name

4. changing file directory at runtime without using a variable in prop:name

5. Directory and long file names

6. Getting list of file names for current directory?

7. naming files/directories

8. Way to get file names from a directory?

9. file dialog doesn't work with spaces or non-list directory names

10. get directory name of file being executed

11. Reading program files from the directory.

12. Read all text files in a directory

 

 
Powered by phpBB® Forum Software