![Get directory location on Magento 2 Get directory location on Magento 2](https://www.johnperricruz.com/wp-content/uploads/2018/08/magneto-posts.jpg)
<?php namespace Vendor\Module\Location; use Magento\Framework\App\Filesystem\DirectoryList; class YourClass implements AnotherClass{ protected $filesystem; public function __construct( DirectoryList $filesystem ){ $this->filesystem = $filesystem; } public function foo(){ $pub = $this->filesystem->getPath('pub'); //pub can be changed into other folders } } ?>