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.

<?php

/**
 * @author  Rakesh Jesadiya
 * @package Rbj_GetPath
 */

namespace Rbj\GetPath\Block;

class GetPathBlock extends \Magento\Framework\View\Element\Template
{
	public function __construct(
            \Magento\Framework\View\Element\Template\Context $context,
	    \Magento\Framework\Module\Dir\Reader $moduleReader,
            array $data = []
	) {
	    $this->moduleReader = $moduleReader;
            parent::__construct($context, $data);
	}

	public function getModuleEtcDirectory():
	{
	    $viewDir = $this->moduleReader->getModuleDir(
	        \Magento\Framework\Module\Dir::MODULE_I18N_DIR,
	        'Rbj_GetPath'
	    );
	    return $viewDir;
	}

	public function getModuleI18nDirectory():
	{
	    $viewDir = $this->moduleReader->getModuleDir(
	        Magento\Framework\Module\Dir::MODULE_I18N_DIR,
	        'Rbj_GetPath'
	    );
	    return $viewDir;
	}
}

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.