Magento 2 Get Current Module directory full path programmatically.

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

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, view or Controller.

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.