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 7032505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:56:39+00:00 2026-05-28T00:56:39+00:00

I have a mostly-working piece of code to read a directory, output each folder

  • 0

I have a mostly-working piece of code to read a directory, output each folder name and count the files and the total size of the files in that directory. But for some reason it is skipping over some folders and not inserting the information into my database.

My Code:

<?php
if ($handle = opendir('E:/')) {

    while (false !== ($entry = readdir($handle))) {
        if ($entry != '$RECYCLE.BIN' && $entry != 'System Volume Information') {
        $exists = mysql_query("SELECT * FROM comics WHERE title LIKE '".$entry."%'");
        $exists1 = mysql_num_rows($exists);
            if ($exists1 != 1) {
            $directory = "E:/".$entry;
            $filecount = count(glob($directory."/"."*.*"));
            $size = 0; 
            $d = new RecursiveIteratorIterator( 
            new RecursiveDirectoryIterator($directory),  
            RecursiveIteratorIterator::SELF_FIRST 
            ); 

            foreach($d as $file){ 
            $size += $file->getSize(); 
            } 

                mysql_query("INSERT INTO comics (title, pages, size, storage_id) VALUES ('".$entry."\n', '".$filecount."', '".number_format($size/1048576, 2)."', '2')");
                print "<li>Inserted <b>".$entry."</b> With A File Count Of <b>".$filecount."</b> & A Total Size Of <b>".number_format($size/1048576, 2)."</b> MB.</li>";
            }
        }
    }
}
?>

It skips over simple folder name like Beyond The Wall of Sleep and does not add them to the database although it does echo the output as if it did input it into the database. Where am I going wrong?

Output Example (Folders not added but they still get listed):

•Inserted Ay Papi 1 With A File Count Of 22 & A Total Size Of 2.59 MB.
•Inserted Beyond The Wall of Sleep With A File Count Of 26 & A Total Size Of 14.92 MB.
•Inserted Fall of Cthulhu With A File Count Of 22 & A Total Size Of 7.57 MB.
•Inserted Heavy Metal - Fantasy Special With A File Count Of 98 & A Total Size Of 49.66 MB.
  • 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-05-28T00:56:40+00:00Added an answer on May 28, 2026 at 12:56 am

    When you add the entry to the DB:

    $sql = "INSERT INTO comics
            (title, pages, size, storage_id)
            VALUES ('".$entry."\n', '".$filecount."', '".number_format($size/1048576, 2)."', '2')";
    mysql_query($sql);
    print "<li>$sql</li>";
    

    Then get the string you are trying to input into MySQL, go to phpmyadmin or to terminal mysql, and try to insert that query. You will get mysql error.

    Another way to debug it would be:

    $sql = "INSERT INTO comics
            (title, pages, size, storage_id)
            VALUES ('".$entry."\n', '".$filecount."', '".number_format($size/1048576, 2)."', '2')";
    $res = mysql_query($sql);
    print "<li>$sql</li>";
    if (!$res)
    {
      echo "Mysql Error: " . mysql_error();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jqGrid 3.5 (full) mostly working. I have it retrieving data with the
I have this thing working mostly. What I don't get is, if I have
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have the following mostly ok code: my $results = { data => [
I'm working on a webservices client app and I have it mostly working. I
I am starting a job with a mid size company working mostly on writing
Greetings, Until now I have mostly been working with google maps v2. I am
I have a working or mostly working POM that fetches all and exactly just
I have Museo-300 mostly working with @font-face, but certain letter combinations like ff and
In the past my development team we have mostly done waterfall development against an

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.