Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Files......

  1. #1
    New Coder
    Join Date
    Jun 2002
    Location
    Paris, France
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Files......

    Is there a way to get a list of files(a,d directories) in a specific directory.

    Suppose in directory images/ you have:
    icon.gif
    bla.jpg
    simeys/

    Is there anyway to get a list of those 3 items in php?
    I don't suffer from insanity, I enjoy every single minute of it!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $opdir opendir('gallery/bigpics');
    while (
    false!==($file readdir($opdir))) {
    if(
    $file!=="." && $file!=="..") {

    echo 
    'I found .......'.$file.'
    '
    ;

    }
    }
    closedir($opdir); 
    basically, open directory, read directory, test that the file found
    isn't named dot or dotdot (dot '.' is the directories name - eg a
    file telling the dir what its own name is, dotdot '..' is something to
    do with the parent directory -- or so I'm led to believe) and echo
    it, then close the directory.

    Edit: change the opendir('xxxxxxxxxxx') to target your named
    directory - you could use opendir('.') to scan the dir that the file
    is in.
    The above would show subdirectories as well as files. If you only
    wanted files....
    if(strpos($file,'.') && $file!=="." && $file!=="..")
    should do.
    Last edited by Ökii; 07-06-2002 at 01:00 PM.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •