Magento2 – How to get Directory of a Module

Magento2 – How to get Directory of a Module
Here is the code how to load your module directory:
     ...
     private \Magento\Framework\Module\Dir\Reader $dir;

     public function __construct(\Magento\Framework\Module\Dir\Reader $dir)
     {
          $this->dir = $dir;
     }
     
     ...
        echo "Directory : ".$this->dir->getModuleDir('', 'Knowthemage_Hello');
     ...

Leave a Reply

Your email address will not be published. Required fields are marked *