Jump to content

FilesystemIterator is showing more files that whats stated in the drive properties.


jasonc310771

Recommended Posts

$dir = "L:";
$flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS;// some flags to filter . and .. and follow symlinks
$iterator = new \RecursiveDirectoryIterator($dir, $flags);// create a simple recursive directory iterator
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);// make it a truly recursive iterator

foreach ($iterator as $path) {
if ($path->isDir()){continue;}

// rest of code

}

Very strange but with one of my drive the code above shows the correct number of files but the other larger drive the code is showing way more than double the actual number of files and still going.  I changed the settings to show all hidden files/folder and select all files/folders then I use right click, properties.  There is nothing in any of the recyclebin. Still the number of files the code above states is way more than that shown in properties.

How can this be ?

Link to comment
Share on other sites

ok so I removed that flag but still the same thing.  Like before it is restarting the scan and duplicating the results in the db table.

It shows error..  access denied for system volume information folder and restarts.  But I do not want that indexed, just all files.

In case there is something else I have wrong here is the complete code.

<!DOCTYPE html><html lang="en"  xml:lang="en"><head><title>GetFiles.php</title></head><html><body><?php
 ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
define('DB_USER', 'root'); define('DB_PASSWORD', ''); define('DB_HOST', 'localhost'); define('DB_NAME', 'mydupcleaner');

function db_query($mysqli, $query) { $result = $mysqli->query("$query"); return $result; }
$mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MySQL: '.mysqli_connect_error());

define('DBTableName', 'filesfrom-m');
$dir = "M:";
$system_volume_information = "M:/System Volume Information";

$flags = \FilesystemIterator::SKIP_DOTS;// some flags to filter . and .. and follow symlinks
$iterator = new \RecursiveDirectoryIterator($dir, $flags);// create a simple recursive directory iterator
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);// make it a truly recursive iterator

foreach ($iterator as $path) {
			if ($path->isDir() ||
			 $path == $system_volume_information){
			 continue;}
				$ext = pathinfo($path, PATHINFO_EXTENSION);
				$query = "INSERT INTO `" . DBTableName . "` (`dateAddedToDB`, `fullpath`, `ext`
				) VALUES 
				('" . $mysqli->real_escape_string(gmdate("Y-m-d H:i:s")) . "',
				'" . $mysqli->real_escape_string($path) . "',
				'" . $mysqli->real_escape_string($ext) . "')"; db_query($mysqli, $query);

}
?>
done</body></html>

 

Edited by jasonc310771
Link to comment
Share on other sites

What do you mean by "restarting"? The loop won't actually restart, of course. Are you remembering to truncate the table before every run of this script?

If you're getting "too many" files then compare what files you're getting versus what files you expect. The difference would have to be somewhere in there, but without knowing it then you'd have to guess.

Link to comment
Share on other sites

The script starts in the browser (FireFox) and runs for about 20 minutes, the error shows access denied

Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(l:\System Volume Information,l:\System Volume Information): Access is denied. (code: 5)' in C:\xampp\htdocs\GetFiles.php:27 Stack trace: #0 [internal function]: RecursiveDirectoryIterator->__construct('l:\\System Volum...', 4096) #1 C:\xampp\htdocs\GetFiles.php(27): RecursiveDirectoryIterator->getChildren() #2 {main} thrown in C:\xampp\htdocs\GetFiles.php on line 27

The number of files at this point is only some of the files (121304) it then stores the same files from the start of the list which has already been through.

Link to comment
Share on other sites

Yeah, there's no way 121k files should take 20 minutes unless you have an incredibly slow hard drive. Like, a tape drive might even be faster.

I can't help but notice that your error message doesn't match the code: it says you're creating a RDI on I:\System Volume Information while your code clearly says it creates one on M:...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.