Mix Files and Folders When Sorting in Windows Explorer
Interleave files and folders when sorting Explorer by any column, instead of always grouping all folders before (or after) all files
Author: Extremenis

Mix files and folders when sorting
Windows Explorer always lists all folders before (or after, when sorting
descending) all files, regardless of which column is sorted by. This is
hardcoded shell behavior, not a UI setting, and it's independent from
"Group by".
This mod removes that separation: a folder and a file are compared according
to the selected column's value (name, date, ...) instead of the folder
automatically winning. Folder-vs-folder and file-vs-file comparisons are left
to the shell untouched, so Explorer's own ordering still applies there.
Only real directories count as folders here. Items that Explorer shows as
browsable but stores as files — .zip and other compressed folders, folder
shortcuts — are treated as files, which is what stock Explorer does for its
folders-first rule too.
Scope
This only affects regular file-system folders (the CFSFolder shell object,
i.e. anything you'd browse to on disk). Special views such as Libraries,
"This PC", and search results use different, independent shell folder
implementations that this mod doesn't touch, so folders may still be grouped
first there. The Desktop is a composite view that delegates comparisons
between two file-system items to the backing CFSFolder, so desktop icon
sorting is affected.
The mod is also scoped to explorer.exe only, so common file/save dialogs in
other applications — which use the same CFSFolder implementation, just in
a different process — keep the default folders-first ordering.
Sorting by Size is left to the shell entirely. Folders report an empty size, so
that column never interleaved on its own, and
explorer-details-better-file-sizes
already owns it — see below.
Sorting by Type does not interleave either, for a different reason: the Type
column carries PKEY_ItemTypeText ("File folder", "Application extension"),
which isn't one of CFSFolder's columns at all — Explorer sorts it outside
CFSFolder::CompareIDs, so the folders-first grouping there is out of this
mod's reach.
Interaction with explorer-details-better-file-sizes
explorer-details-better-file-sizes
hooks the same CFSFolder::CompareIDs function and has its own
"Mix files and folders when sorting by size" setting (sortSizesMixFolders,
on by default). Both hooks delegate to the original for anything they don't
handle, so they chain rather than fight: that mod handles the Size column,
this one handles the rest.
To keep that clean, this mod returns the Size column to the original
comparison untouched. That mod's sortSizesMixFolders setting therefore stays
authoritative for Size whether it's on or off, and the result no longer depends
on which mod's hook happens to run first.
Known limitations
The shell's own file-vs-file comparison and this mod's folder-vs-file
comparison are separate pieces of code, so they can disagree at the margins
and place a folder in a spot that looks slightly off relative to nearby
files. Known cases: date columns reported as VT_DATE are compared as a
double (~ms resolution) where the shell compares FILETIME at 100 ns;
locale collation of punctuation or accented characters may differ; and a
blank value is sorted before any present value, which the shell doesn't
necessarily do for sparsely-populated columns (Date taken, Length,
Dimensions).
Credit / related mod
The CFSFolder hooking scaffolding (symbol hook, hook lifetime tracking,
CompareIDs hook skeleton) is derived from m417z's
explorer-details-better-file-sizes, which is licensed under GPLv3; this mod
is licensed under GPLv3 for that reason.