SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Grab File Loop

  1. #1
    SitePoint Addict dgroves's Avatar
    Join Date
    Jan 2007
    Location
    Bath, UK
    Posts
    364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grab File Loop

    Hi,

    I need to write a script that will do the following ASAP:

    • look in a spacific directory
    • take the first file, include it into a file and do something with the varibles inside
    • repeat with the next file
    • keep doing this until it has run-out of files

    Ideas? Suggetions?

    Thanks in advance,
    Dan

  2. #2
    SitePoint Addict dgroves's Avatar
    Join Date
    Jan 2007
    Location
    Bath, UK
    Posts
    364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SCRAP THAT!

    Got a better solution now anyways!

  3. #3
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Assuming you have a variant of PHP 5, you could use SPL.

    PHP Code:
    <?php
    foreach(new DirectoryIterator('/path/of/your/choice/') as $oFile)
    {
        if(
    $oFile->isFile())
        {
            include(
    realpath($oFile->getPathname()));
            
    /*
                Do stuff with included vars.
            */
        
    }
    }
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

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