Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function searchFiles($dir, $startDate, $endDate, $searchTerm) {
- $files = glob($dir . '/*');
- $result = array();
- foreach($files as $file) {
- if(is_dir($file)) {
- $result = array_merge($result, searchFiles($file, $startDate, $endDate, $searchTerm));
- } else {
- if(preg_match("/$searchTerm/", basename($file))) {
- $fileTime = filemtime($file);
- if($fileTime >= $startDate && $fileTime <= $endDate) {
- $result[] = $file;
- }
- }
- }
- }
- return $result;
- }
- $dir = '/path/to/directory';
- $startDate = strtotime('2022-01-01');
- $endDate = strtotime('2022-12-31');
- $searchTerm = 'myfilename';
- $result = searchFiles($dir, $startDate, $endDate, $searchTerm);
- foreach($result as $file) {
- echo $file . "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement