Get directory location on Magento 2

Get directory location on Magento 2
<?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
	    }
	}

?>			

Leave a Reply