I am writing a function to recursively traverse directories and return the files in them. The directories store call recordings within filepaths that follow the naming convention 'YY/mm/dd'
.
An example filepath will look like so /vhosts/example.org/private/recordings/2018/11/21/user@example.org_XXXXXXXXX
My script is supposed to traverse all the possible filepaths for a given time period and then iterate through the results filtering out the ones that match a certain person. Since the files are stored in this manner I am not using filemtime()
instead I am building a regular expression to match against the filepath of the recording.
//make the date into a regular expression blocks
//this is only a small abstract of the logic that builds the regular expression
$year = date_format($start_date, 'Y');
$months = '([' . date_format($start_date, 'm') . '-' . date_format($end_date, 'm') . '])';
$days = '([' . date_format($start_date, 'd') . '-' . date_format($end_date, 'd') . '])';
//lets assume this was the regex built by that logic
$regex = preg_quote("2018/11/21");
//traverse and build the iterator
$directory = new RecursiveDirectoryIterator($root_directory);
$results = new RecursiveIteratorIterator($directory);
if($condition){
$results = new RegexIterator($results, "#$regex*#", RecursiveRegexIterator::GET_MATCH);
}
My question is does the RegexIterator match against the filename or filepath or both? Without entering the if statement I get this response. When I enter the if statement I get an empty object. I haven't implemented the check for a particular user yet, I am first making sure I can narrow the time period accordingly.
object(SplFileInfo)#9 (2) {
["pathName":"SplFileInfo":private]=>
string(112) "/vhosts/example.org/private/recordings/2018/11/21/user@example.org_82342342.wav"
["fileName":"SplFileInfo":private]=>
string(61) "user@example.org_82342342.wav"
}