We have a .net console app that does the similar thing you did. First you can get the google drive api package for .net. then you can assign the permission for every folder recursively based on the file id.
In google api, the file and fold are the same type File. so the id is the key to find the folder as well as the files under the folder and subfolders.
But it is a time consuming process. If one time job, you might be able to get help from permission inherit. Honestly I didn't try that way, but I believe it is worth to try. However, no matter how you still be able to programmatically solve your issue by writing a simple console app.
Good luck,
Terry