Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8456799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:38:29+00:00 2026-06-10T12:38:29+00:00

I have some error_log.txt files, create in /var/www/html/log/’.date(Ymd).’/error_log.txt , The folder table like this.

  • 0

I have some error_log.txt files, create in /var/www/html/log/'.date(Ymd).'/error_log.txt, The folder table like this.

-log-
    |--20120825 -- error_log.txt
    |--20120826 -- 
    |--20120827 -- error_log.txt
    |--20120828 -- error_log.txt

How to make a foreach loop in folder which name as log, then get all the subfolder name and make a judgment if there has error_log.txt in this subfolder?

As the folder table show, 20120826 have no error_log.txt in it, so do not print the folder name.

Finally I need get the folder name: 20120825, 20120827, 20120828

$folder = dirname(__FILE__) . '/../log/';
foreach(glob($folder) as $subfolder){
  if(file_exists($subfolder.'/error_log.txt')){
    echo  $subfolder.'<br />'; //I get nothing.
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:38:30+00:00Added an answer on June 10, 2026 at 12:38 pm
    $folder = dirname(__FILE__) . '/../log/';
    foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder)) as $entry) {
      if ($entry->isFile()) {
        echo $entry, '<br />';
      }
    }
    

    Used in this way, you’ll only get actual files. And if you don’t like the iterator style, use:

    $folder = dirname(__FILE__) . '/log/*';
    foreach(glob($folder) as $subfolder){
      $path = $subfolder . '/error_log.txt';
      if (file_exists($path)) {
        echo basename($subfolder), '<br />';
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code which handles data files and reports an error when it
I have some code like this: EventLog.CreateEventSource(myApp, myAppLog); EventLog.WriteEntry(myApp, Test log message, EventLogEntryType.Error); Now,
We have manage to export data from our mysql table into a .txt file.
I have an HTML document that is using to embed a control. In some
I have the following code: <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd> <html> <head>
I am writing some BASH script and I want it have some error handling
I have defined some Error Messages and my Question is, how to access them
I have to debug some error that is db related and have been continuously
I have some code in my error handler I need to test against a
I have question. I have some app on facebook and getting this error Fatal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.