Searching a hierarchy for progressive node criteria
These things are generally done through backtracking. Which in your case would look somewhat like this:


Go down 3 levels and look for 'a'
If you find some -> perform your magic
If you find none (or if you do, depending on the implementation) -> go up 1 level repeat steps 1-3


Really this is no better than simply searching all directories in the worst case, but there is no way you can guarantee having found all a's without searching every directory anyway (assuming no prior knowledge). However this solution will have a much better average case performance if the a's are always at the maximum level than simply starting to search at level 1, then level 2 etc.

edit: also, regexes are fast because the average CPU performs billions of operations per second. If you're copying files then the copying will be the part slowing it own drastically anyway so you probably should not be too concerned with the performance of your searching algorithm