added File Helper

This commit is contained in:
Jonathan Treffler 2023-09-02 02:47:26 +02:00 committed by root
parent 29aa0d24fa
commit c9d52b4c77

View file

@ -0,0 +1,36 @@
<?php
namespace OCA\GroupfolderFilesystemSnapshots\Helpers;
class FileHelper {
private static function seperateFilesFromFolders($parentDir, $items) {
$files = [];
$folders = [];
foreach($items as $item) {
if(is_dir($parentDir . DIRECTORY_SEPARATOR . $item)) {
$folders[] = $item;
} else {
$files[] = $item;
}
}
return array($files, $folders);
}
public static function getFilesAndFolders($dir) {
$scan = array_diff(scandir($dir), array('..', '.'));
return self::seperateFilesFromFolders($dir, $scan);
}
public static function getFilesizesOfFiles($prefix, array $files) {
$result = array();
foreach($files as $index=>$file) {
$result[$index] = filesize($prefix . DIRECTORY_SEPARATOR . $file);
}
return $result;
}
}