How to get a module's filesystem path programmatically

###Magento 1.x code:

Mage::getConfig()->getModuleDir('etc', 'Df_Localization')

###Magento 2 code:

/**
 * @param string $moduleName
 * @param string $type [optional]
 * @return string
 * @throws \InvalidArgumentException
 */
function df_module_dir($moduleName, $type = '') {
	/** @var \Magento\Framework\ObjectManagerInterface $om */
	$om = \Magento\Framework\App\ObjectManager::getInstance();
	/** @var \Magento\Framework\Module\Dir\Reader $reader */
	$reader = $om->get('Magento\Framework\Module\Dir\Reader');
	return $reader->getModuleDir($type, $moduleName);
}

See also other filesystem topics: