Advertisement
fatalryuu

Untitled

Mar 12th, 2023
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. function searchFiles($dir, $startDate, $endDate, $searchTerm) {
  2. $files = glob($dir . '/*');
  3. $result = array();
  4.  
  5. foreach($files as $file) {
  6. if(is_dir($file)) {
  7. $result = array_merge($result, searchFiles($file, $startDate, $endDate, $searchTerm));
  8. } else {
  9. if(preg_match("/$searchTerm/", basename($file))) {
  10. $fileTime = filemtime($file);
  11. if($fileTime >= $startDate && $fileTime <= $endDate) {
  12. $result[] = $file;
  13. }
  14. }
  15. }
  16. }
  17.  
  18. return $result;
  19. }
  20.  
  21.  
  22. $dir = '/path/to/directory';
  23. $startDate = strtotime('2022-01-01');
  24. $endDate = strtotime('2022-12-31');
  25. $searchTerm = 'myfilename';
  26.  
  27. $result = searchFiles($dir, $startDate, $endDate, $searchTerm);
  28.  
  29. foreach($result as $file) {
  30. echo $file . "\n";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement