0

The issue is the following: I have a huge amount of report files (+10000) and I need to analyze them.

  1. Even on SSD I got problem using filemanager to group and divide them ( maybe is a problem with nautilus ) ...
  2. filename is not very meaning full so it is difficult to remember a particular log file.

Any Idea ?

1 Answer 1

1

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);
    }
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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