I am creating a cron job for a Magento 2 site. This cron job will search for files in


and will then process them.

I already have the cron job setup and can handle processing the file but I am wondering if there are any tools/libraries in magento 2 that can help with this process of finding files.

It is possible to do this without magento just using straight PHP commands but I am wondering if Magento has any tools that could help this process.

Part of the task that I will need to do when detecting these files is handle where they go as they are named in a certain format:



Try glob Function It'll help you to find a file in the folder. Check code for your reference.

$directory = "var/mycsv";
$csvs = glob($directory . "xyz.csv");

foreach($csvs as $csv)
  echo $csv;

I hope it'll help you. :)

  • Great, its work for me. Thanks @Mayank – Dhaduk Mitesh Mar 13 '18 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.