jasonc310771 Posted December 18, 2022 Share Posted December 18, 2022 $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 ? Quote Link to comment https://forums.phpfreaks.com/topic/315661-filesystemiterator-is-showing-more-files-that-whats-stated-in-the-drive-properties/ Share on other sites More sharing options...
requinix Posted December 19, 2022 Share Posted December 19, 2022 Are you sure you want to be following symlinks? Are there any hardlinks on the drive? Quote Link to comment https://forums.phpfreaks.com/topic/315661-filesystemiterator-is-showing-more-files-that-whats-stated-in-the-drive-properties/#findComment-1603701 Share on other sites More sharing options...
jasonc310771 Posted December 19, 2022 Author Share Posted December 19, 2022 (edited) 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 December 19, 2022 by jasonc310771 Quote Link to comment https://forums.phpfreaks.com/topic/315661-filesystemiterator-is-showing-more-files-that-whats-stated-in-the-drive-properties/#findComment-1603703 Share on other sites More sharing options...
requinix Posted December 19, 2022 Share Posted December 19, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315661-filesystemiterator-is-showing-more-files-that-whats-stated-in-the-drive-properties/#findComment-1603704 Share on other sites More sharing options...
jasonc310771 Posted December 19, 2022 Author Share Posted December 19, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315661-filesystemiterator-is-showing-more-files-that-whats-stated-in-the-drive-properties/#findComment-1603708 Share on other sites More sharing options...
requinix Posted December 19, 2022 Share Posted December 19, 2022 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:... Quote Link to comment https://forums.phpfreaks.com/topic/315661-filesystemiterator-is-showing-more-files-that-whats-stated-in-the-drive-properties/#findComment-1603717 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.