PHP to check if file exists in a folder for child ← (PHP, CSS)

one text

I am wanting to have a basic child theme check that works similar to how WP does it.

I have specific files for things like header, footer, content, part etc. much like WP does in its main theme. I want to be able to add a short piece of code in each of those files to check if another (same_named.php) file exists in (dynamic) folder named theme_(anyname).

I did a few tests from much older posts, e.g, PHP Check if dynamic named folder exists

But how do I get it to check for a specific folder and a specific file name that matches the original.

Is there a way to also check for css files as well the same way? I am guessing we can't do the check in the css file itself?

Thanks for your help, it is appreciated.

Source