File Manipulation Code

  Home arrow File Manipulation Code arrow List files in a directory, no subdirec...
FILE MANIPULATION CODE

List files in a directory, no subdirectories
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2004-03-26

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    This snippet will list files in drop down menu, truncate the file extension and capitalize the first letter of the file. I use it on my "theme changer" script but is useful if you want to only list the files in a directory and not its subdirectory.

    By : shockingbird

    <?
    /*
    ABOUT:
    This snippet will list all the files in the directory of your
    choice, truncate the file extension, capitalize the first letter and
    put it all in a drop down menu. The script will not list subdirectories so
    all you see are the files in your directory.

    Feel free to use or modify to your liking.

    USAGE:
    Change the $dirpath variable the directory you want to list.

    AUTHOR:
    Written by shockingbird
    Visit www.glomer.net for more information
    tate at tatenations dot com for any questions
    */
    echo "<form>";
    //Looks into the directory and returns the files, no subdirectories
    echo "<select name='yourfiles'>";
    //The path to the style directory
    $dirpath = "/path/to/your/directory";
    $dh = opendir($dirpath);
    while (false !== ($file = readdir($dh))) {
    //Don't list subdirectories
    if (!is_dir("$dirpath/$file")) {
    //Truncate the file extension and capitalize the first letter
    echo "<option value='$file'>" . htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))) . '</option>';
    }
    }
    closedir($dh);
    //Close Select
    echo "</select>";
    echo "</form>";
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More File Manipulation Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    FILE MANIPULATION CODE ARTICLES

    - Bandwidth Control with pure PHP
    - Eazy Gallery
    - file_get_contents for PHP < 4.3.0
    - PHP Class: Image Snapshot 1.3
    - Universal downloader
    - Image Gallery v2.0
    - Free/Used Disk Space
    - Directory Lister
    - Directory image view, with selective hidden
    - Move or Copy a Directory (and files and sub ...
    - Ensure_Sub_Directory_Exists
    - Wedit
    - Form Examples Text Boxes to Drop Downs
    - myFiles
    - List files in a directory, no subdirectories


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 7 - Follow our Sitemap