How to get count of datasets inside the particular folder space

I want to get the count of datasets inside the particular folder into space. Based on the count I need to create a new folder once the dataset count is more than 200 and keep all other dataset which make count more than 200.

You can use the catalog API for that purpose:
https://docs.dremio.com/rest-api/catalog/
When requesting a folder or a space, you will be able to know the children, their type (CONTAINER, DATASET OR FILE), the containerType (eg FOLDER) or datasetType (eg PROMOTED)