Skip to main content
added 644 characters in body
Source Link
Fra
  • 7k
  • 12
  • 65
  • 99

Following code will:

  1. rename each report on the base of its time creation (format ex. 10_50_01 it will be the new filename for a report created a 10:50:01)

  2. Create a new folder (format ex. May-20-2014) for each day and put all report for that day in it

    $pathBase = $MAGE_ROOT_FOLDER . '/var/report/'; $files = glob($pathBase . '*'); // sort by date usort($files, function ($a, $b) { return filemtime($a) < filemtime($b); });

    $pathBase = $MAGE_ROOT_FOLDER . '/var/report/';
    $files = glob($pathBase . '*');
    // sort by date
    usort($files, function ($a, $b) {
        return filemtime($a) < filemtime($b);
    });
    
    foreach ($files as $i => $f) {
       $filename = pathinfo($f, PATHINFO_FILENAME);
       $timeStamp = filemtime($f);
       $toDir = date("F-d-Y", $timeStamp) . '/';
       $newDateName = date("H-i-s", $timeStamp);
    
       echo $i . $filename . ' - ' . $newDateName . ' -> ' . $toDir . '<br/>';
    
       if (!is_dir($pathBase . $toDir)) {
           echo 'Create Dir' . '<br/>';
           mkdir($pathBase . $toDir, 0777, true);
       }
    
      echo 'Rename and Move' . '<br/>';
      rename($f, $pathBase . $toDir . $newDateName);
    }
    

Following code will:

  1. rename each report on the base of its time creation (format ex. 10_50_01 it will be the new filename for a report created a 10:50:01)

  2. Create a new folder (format ex. May-20-2014) for each day and put all report for that day in it

    $pathBase = $MAGE_ROOT_FOLDER . '/var/report/'; $files = glob($pathBase . '*'); // sort by date usort($files, function ($a, $b) { return filemtime($a) < filemtime($b); });

Following code will:

  1. rename each report on the base of its time creation (format ex. 10_50_01 it will be the new filename for a report created a 10:50:01)

  2. Create a new folder (format ex. May-20-2014) for each day and put all report for that day in it

    $pathBase = $MAGE_ROOT_FOLDER . '/var/report/';
    $files = glob($pathBase . '*');
    // sort by date
    usort($files, function ($a, $b) {
        return filemtime($a) < filemtime($b);
    });
    
    foreach ($files as $i => $f) {
       $filename = pathinfo($f, PATHINFO_FILENAME);
       $timeStamp = filemtime($f);
       $toDir = date("F-d-Y", $timeStamp) . '/';
       $newDateName = date("H-i-s", $timeStamp);
    
       echo $i . $filename . ' - ' . $newDateName . ' -> ' . $toDir . '<br/>';
    
       if (!is_dir($pathBase . $toDir)) {
           echo 'Create Dir' . '<br/>';
           mkdir($pathBase . $toDir, 0777, true);
       }
    
      echo 'Rename and Move' . '<br/>';
      rename($f, $pathBase . $toDir . $newDateName);
    }
    
Source Link
Fra
  • 7k
  • 12
  • 65
  • 99

Following code will:

  1. rename each report on the base of its time creation (format ex. 10_50_01 it will be the new filename for a report created a 10:50:01)

  2. Create a new folder (format ex. May-20-2014) for each day and put all report for that day in it

    $pathBase = $MAGE_ROOT_FOLDER . '/var/report/'; $files = glob($pathBase . '*'); // sort by date usort($files, function ($a, $b) { return filemtime($a) < filemtime($b); });