[GH-ISSUE #1329] Date Modified Sort Interleave Folders and Files #848

Open
opened 2026-03-02 16:01:47 +03:00 by kerem · 1 comment
Owner

Originally created by @gustebeast on GitHub (Jul 1, 2025).
Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1329

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.

Originally created by @gustebeast on GitHub (Jul 1, 2025). Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1329 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.
Author
Owner

@smalos commented on GitHub (Jul 2, 2025):

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.

<!-- gh-comment-id:3029236407 --> @smalos commented on GitHub (Jul 2, 2025): 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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tinyfilemanager#848
No description provided.