There are a few instances in your flow where you can utilize a Filter Array action instead of looping through each file or item returned.
For example, in the beginning of your flow, you are using an Apply to Each action to loop through every single file in a folder and checking if each file matches your condtions.
Instead, if you use a Filter Array action you could filter out the files that match your conditions and loop through those filtered files. It would be much more efficient and then looping through every file to run a check.