Can I read a file in a directory?

Can I read a file in a directory?

Discussion in 'Web Programming' started by robertdn, Jan 27, 2015.

  1. robertdn

    robertdn Moderator

    Messages:
    112
    Likes Received:
    14
    Trophy Points:
    18
    Ratings:
    +15 / 0 / -0
    How is everybody today?

    I need your advice. I have about 700 files located in a directory named “Batch” and I need to read every file in this directory.

    My question is, how do I go about reading each file?

    Thank you for your aid.
     
    Loading...
  2. HansM

    HansM New Member

    Messages:
    20
    Likes Received:
    1
    Trophy Points:
    3
    Ratings:
    +1 / 0 / -0
    There are a number of options available for you depending upon the programming language you are familiar with.

    Personally, I would use the following code. I hope it helps or gives you a guideline to what to look for:

    Code:
    foreach (scandir(".") as $file) {
    if (is_file($file)) {
    function_name(file_get_contents($file));
    }
    }