Magento 2 Get Current Module directory full path programmatically.

You can Retrieve a full path to a directory of a certain type within a module using Magento 2.

Using this article, When you need your current module path using programmatic way, You can fetch the current working module path by given code snippets.

Magento\Framework\Module\Dir and Magento\Framework\Module\Dir\Reader class used for getting the full path of Current modules any directory path like i18n, etc, Model,  Plugin, Helper,  API, view or Controller folder.

You need to pass the current module name in getModuleDir() second arguments. Here module name is Rbj_GetPath.

call from the template file,

echo $block->getModuleI18nDirectory();
Output: /var/www/html/magento231/app/code/Rbj/GetPath/i18n
echo $block->getModuleEtcDirectory();
Output: /var/www/html/magento231/app/code/Rbj/GetPath/etc

You can get controller and view directory as same way by replacing MODULE_CONTROLLER_DIR and MODULE_VIEW_DIR respectively.