How to rename file programmatically Magento 2?

You can rename the file names in Magento by providing the source path and destination path.

I have tested the given functionality to rename the file names under the pub directory. You can do it for outside pub directory but you need to change __construct() method $this->directory argument value.

$this->directory = $filesystem->getDirectoryWrite(DirectoryList::PUB); Continue reading “How to rename file programmatically Magento 2?”

How to write text file and create directory in Magento 2 standard way?

You can write the content dynamically in text(.txt) file using Programmatic way with Magento 2 Standard approach.

Sometimes you need to create a directory and write a text file in the specific location of the system, You can add the content with interface Magento\Framework\Filesystem\Directory\WriteInterface. Continue reading “How to write text file and create directory in Magento 2 standard way?”

How to Delete directory in Magento 2 Programmatically?

You can delete any directory from the given path programmatically Using Magento 2 without manual delete.

For example, You have created a directory in var folder at a time of developing functionality and in the future, want to delete the directory from the var folder, You can do it using delete() method of WriteInterface. Continue reading “How to Delete directory in Magento 2 Programmatically?”