How to create a directory in Magento 2 Programmatically?

How to create a new Folder or Directory Magento 2?
When you are working for a custom module in Magento 2 and need to add the log to the custom file inside the var/log folder.

Log folder contains the multiple log files and if you want to create a new folder for your custom log of the module, You can create a New Folder programmatically using WriteInterface.

A simple demo to create a new folder or directory under the var/log section called Payment, We are adding our custom module log inside the payment folder, We first create a new Payment folder,

The new Payment module will be generated after calling the createDirectory() method.

If the payment folder doesn’t exists create a new folder and return true If any issue occurred result will be false.