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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:49:22+00:00 2026-06-01T06:49:22+00:00

I have been working on a recursive directory scan which scans folders and adds

  • 0

I have been working on a recursive directory scan which scans folders and adds them to my mysql database if it is not already there. The only problem I have is no matter how i seem to write the Check part of my form it still skips over some records and/or it detects it as already being there when there is something with the same name that ends with a 0. Examples + Code Below.

Table:

CREATE TABLE IF NOT EXISTS `comics` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `publisher` varchar(255) NOT NULL,
  `arc` varchar(255) NOT NULL,
  `issue` int(5) NOT NULL,
  `title` varchar(255) NOT NULL,
  `plot` longtext NOT NULL,
  `price` varchar(20) NOT NULL DEFAULT '0',
  `files` int(255) NOT NULL,
  `size` varchar(255) NOT NULL,
  `cover` text NOT NULL,
  `month` int(2) unsigned zerofill NOT NULL,
  `day` int(2) unsigned zerofill NOT NULL,
  `year` int(4) unsigned zerofill NOT NULL,
  `added` date NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `arc` (`arc`,`issue`,`title`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Records:

INSERT INTO `comics` (`id`, `publisher`, `arc`) VALUES
(10463, '', 'Green Wake 10');
INSERT INTO `comics` (`id`, `publisher`, `arc`) VALUES
(10462, '', 'Green Wake 1');

If the first insert is present before the second insert then the second one comes back as already being in the database.

Code As It Sits Now:

<?php
$base = "D:/comics/";
if (isset($_REQUEST['sub'])) {
$sub = $_REQUEST['sub'];
echo "<h2>Scanning Comics Starting With ".$sub."</h2>";
    if ($handle = opendir('D:/comics/'.$sub.'/')) {

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

                foreach($d as $file){ 
                $size2 += $file->getSize(); 
                } 
                $size = $size2/1024;
                $modified = date("Y-m-d", filemtime($directory)); 

                    mysql_query('INSERT INTO comics (arc, files, size, added) VALUES ("'.$entry.'", "'.$filecount.'", "'.$size.'", "'.$modified.'")');
                    print "<li>Inserted <b>".$entry."</b> With A File Count Of <b>".$filecount."</b> & A Total Size Of <b>".$size."</b> MB Last Modified On <b>".$modified."</b>.</li>";
                }
            }
        }
    }
}    
    ?> 

Different Check Queries I Tried:

$exists = mysql_query('SELECT * FROM comics WHERE arc LIKE "'.$entry.'%"');
// Returns As Already Being In The Database.

$exists = mysql_query('SELECT * FROM comics WHERE arc = "'.$entry.'"');
// Returns The Successfully Imported Message (but doesn't execute the insert query) For All Folders Found. Even If It Is There Or Not.

What would be a more precise check method?

  • 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-01T06:49:23+00:00Added an answer on June 1, 2026 at 6:49 am

    It is normal because of this query

    $exists = mysql_query('SELECT * FROM comics WHERE arc LIKE "'.$entry.'%"'); 
    'Green Wake 10' like 'Green Wake 1%' will return true
    

    The % operator tells that it accept any char. In you rule, the test will be successfull if the left value starts with ‘Green Wake 1’ and finish with any char (or even no more char)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been working on query which uses compute by clause for avg and
I have been working on on an AJAX chat application using php, mysql. It's
Have been working on this question for a couple hours and have come close
I have been working on Eclipse recently. I am fairly new to java programming,
I have been working on a Windows Mobile app for a little while now
I have been working on keeping things object oriented for my project. Currently, I'm
I have been working on this problem for 2 days now and it's an
I have been working on a django app on my local computer for some
I have been working with Exceptions lately. I think it makes sense to log
I have been working on a project for a month or so now to

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.