Not sure if C: is the correct location to put SQL files as you are then sharing the disk I/O with the OS.
BUT one way you could do this would be with the windows file permissions. You can allow read/write operations on subfolder1 and subfolder2, but only allow read operations on folder1. This way, if someone tried to restore a database to folder1, they would get a permission denied error. This would affect ALL files in folder1 though, not just newly created ones. So if you had master (for example) in folder1, you would likely get errors starting the instance.
Apart from that, I am not aware of any way to restrict it.
The above is all just my opinion on what you should do.
As with all advice you find on a random internet forum - you shouldn't blindly follow it. Always test on a test server to see if there is negative side effects before making changes to live!
I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.