brainite / OfficeMacros

GNU General Public License v3.0
0 stars 0 forks source link

Macro to count items in Outlook folders #3

Open stackpr opened 4 years ago

stackpr commented 4 years ago

Once the count macro is run on both old and new, they can be merged:

<?php
$files = array(
  'active.txt' => array(),
  'backup.txt' => array(),
);
$all = array();

foreach ($files as $path => &$data) {
  foreach (file($path) as $line) {
    list($folder, $count) = explode("\t", $line, 2);
    $data[$folder] = $count;
    $all[] = $folder;
  }
}
unset($data);

$all = array_unique($all);
sort($all);

echo "Folder\tActive\tBackup\n";
foreach ($all as $folder) {
  $line = $folder;
  foreach ($files as $data) {
    if (isset($data[$folder])) {
      $line .= "\t" . intval($data[$folder]);
    }
    else {
      $line .= "\t-";
    }
  }
  echo $line . "\n";
}