tinyfilemanager icon indicating copy to clipboard operation
tinyfilemanager copied to clipboard

Date Modified Sort Interleave Folders and Files

Open gustebeast opened this issue 6 months ago • 1 comments

Couldn't find a place to make a feature request so making it here. Would be nice if there was a config option such that when you sort by date modified (or anything for that matter) it would interleave folders and files rather than showing all the files sorted, then all the folders sorted.

gustebeast avatar Jul 01 '25 22:07 gustebeast

You could add an option (e.g., interleave_sorting= true) to allow the user to choose whether to interleave files and folders in the listing. When interleaving is enabled, display all items (files and folders) in a single array and sort them together according to the selected criterion.

Then, instead of separating $files and $folders, create a single array $items where each element stores name, type (file/folder), modification time, etc. Sort $items with your chosen sorting method. Display all $items in order.

$items = [];
foreach ($objects as $file) {
    if ($file == '.' || $file == '..') continue;
    $full_path = $path . '/' . $file;
    $is_file = is_file($full_path);
    $is_dir = is_dir($full_path);
    if ($is_file || $is_dir) {
        $items[] = [
            'name' => $file,
            'is_dir' => $is_dir,
            'modif' => filemtime($full_path),
            // add other properties as needed
        ];
    }
}

// Example: Sort by modification time, newest first
usort($items, function($a, $b) {
    return $b['modif'] <=> $a['modif'];
});

In the HTML output, loop through $items and display each one, using $item['is_dir'] to choose the folder or file icon/actions.

smalos avatar Jul 02 '25 20:07 smalos