Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Created January 28, 2019 09:10
Show Gist options
  • Save remcotolsma/b4a78e9e6cfebe21319ed45bb676fa4c to your computer and use it in GitHub Desktop.
Save remcotolsma/b4a78e9e6cfebe21319ed45bb676fa4c to your computer and use it in GitHub Desktop.
Check if all files within a range are in a directory.
<?php
global $argv;
$dir = __DIR__;
if ( isset( $argv[1] ) ) {
$dir = $argv[1];
}
$numbers = range( '201800001', '201800620' );
if ( ! is_dir( $dir ) ) {
var_dump( $dir );
exit( 1 );
}
$files = scandir( $dir );
// @https://stackoverflow.com/a/10473026/6411283
function startsWith($haystack, $needle) {
// search backwards starting from haystack length characters from the end
return $needle === ''
|| strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
foreach ( $numbers as $number ) {
$number = strval( $number );
foreach ( $files as $file ) {
if ( startsWith( $file, $number ) ) {
continue 2;
}
}
echo $number, PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment