-1

Is it possible to sort by both name and date in windows detail view?

First sort by name so that I can see the range of product I want and then by date in order to get the latest version of the product?

I can't use windows search as I've tried everything I can to fix the fact that it's searching at a snail's pace and considering the fact that there's over 20000 items in that folder, it literally takes hours to find one thing.

To make this clearer:

  1. Yes, I want to do this in Windows Explorer.
  2. No I don't have duplicate file names.
  3. I want it to be listed according to name first then date after. I came into this company recently and their file structure was completely messed up. I only recently managed to start adding files with names like "Kellogg's Corn Flakes 1kg 2021". Before this it was named "kelloggs-corn-flakes" and "kelloggs corn flakes NEW". The "NEW" file could be from 2014 while the one with hyphens might be from 2016 or 2017. Meaning that there are thousands of files that aren't named with a standard that makes sense.
  4. Windows Search takes HOURS to complete on that pc even after rebuilding the index and I need results quickly as I often have to get promotional material out within a day or two. Promotions that I do, often have upwards of 100 items per promo. The reason why I want to be able to sort using both name and date is because if I can sort by both conditions I'll be able to look to the right in details view after just typing out the first few characters in the name and I'll be able to get the most recent one as the first result instead of having to scour the folder manually in order to be able to find what I'm looking for.

Thanks for your advise Scott.

1
  • As I read this, you want to modify the sort order in the Search Results for... window, is that correct? If so, I think I can help. I jsut wrote a PowerShell script that could help. Is this what you're looking for? Commented Mar 8, 2021 at 2:39

2 Answers 2

0

First of all, I assume that you are talking about File Explorer, previously known as Windows Explorer (implemented by explorer.exe).

The answer is Yes and No.

Yes, in Explorer’s Details view, you can sort by two columns by clicking on the header of the first (primary sort) column, as usual, and then Shift+clicking on the second.

No, what you’re asking for is not possible, because you can’t sort on a substring of the filename.  If you use “Name” as your primary sort key, Windows will never look at the secondary key, because you can’t have two (or more) files in the same folder with the exact same name.

1
0

Normally, Windows will save view customizations for the SearchResults folder for a given source folder. That is to say if you search "FolderXYZ" and then modify the view settings of "Search Results in FolderXYZ" and then close it, a subsequent search of "FolderXYZ" should remember your changes. If that's not that case, you've most likely maxed out on saved views (limit 5000). Views are saved in the fegistry. The easiest way to check if you';'ve maxed out is to copy & paste this code into PowerShell window:

((gp "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU").Nodeslots).count

Sample Output:

PS C:\> ((gp "HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\BagMRU").Nodeslots).count
963
PS C:\>

If you've hit 5000, you need to delete the BagMRU and Bag keys, which deletes all saved folder vidws. That can be done via RegEdit, merging a .reg file, or using this PowerSehll:

sl 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell'
'BagMRU', 'Bags' | Remove-Item -Recurse

If you do that, the first time you search a folder, it should display the SearchResults view using the system default (Content for most FolderTypes). But any changes you make to the view settings should be saved & used by subsequent searches of the same folder. But whenever a given path is searched for the first time, it will use the default SearchResults template for the associaated FolderType.

    Base FolderType | Library              LibraryFolder              SearchResults            OneDriveBase             
    =============== | =======              =============              =============            ============             
           Contacts | Contacts.Library     Contacts.LibraryFolder     Contacts.SearchResults                            
          Documents | Documents.Library    Documents.LibraryFolder    Documents.SearchResults  StorageProviderDocuments 
            Generic | Generic.Library      Generic.LibraryFolder      Generic.SearchResults    StorageProviderGeneric   
              Music | Music.Library        Music.LibraryFolder        Music.SearchResults      StorageProviderMusic     
           Pictures | Pictures.Library     Pictures.LibraryFolder     Pictures.SearchResults   StorageProviderPictures  
             Videos | Videos.Library       Videos.LibraryFolder       Videos.SearchResults     StorageProviderVideos    
          DOwnloads |                                                 DOwnloads

So, assuming views are being saved, but you would like to set a custom default for SearchResults, this code will allow you to copy the saved view:

### String constans
$ShellKey    = 'HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell'
$BagMRU      = "$ShellKey\BagMRU"
$Bags        = "$ShellKey\Bags"
$ConfirmCopy = @'

Default view set for: {0}
            Based on: "{1}" ( Bag #{2} )
            Key Name: {3}

'@

### Dictonary FOlderTYpeID -> FolderType.CanonicalName
$FTKey     = Get-Item 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes'
$FT_Lookup = $FTKey.GetSubkeyNames() | ForEach{ $hash = @{'{25CC242B-9A7C-4F51-80E0-7A2928FEBE42}'='Network'} } {
     $hash.Add( $_, $FTKey.OpenSubkey($_).GetValue('CanonicalName') )
} { $hash }


$Shell  = New-Object -ComObject shell.application
(Get-Item $BagMRU).Property -match '\d+' | ForEach{
Try{
    [PSCustomObject]@{
        'Bag'  = Get-ItemPropertyValue "$BagMRU\$_" NodeSlot
        'Name' = ( $Shell.NameSpace(( Get-ItemPropertyValue $BagMRU $_ ))).Title
    } 
} Catch {}
} | Where Name -match 'Search Results' |
    Where { (Test-Path "$Bags\$($_.Bag)\Shell") -and (Get-Item "$Bags\$($_.Bag)\Shell").SubKeyCount } | ForEach{
    $Splat = @{
        'NotePropertyName'  = 'Type'
        'NotePropertyValue' = $FT_Lookup[( Get-Item "$Bags\$($_.Bag)\Shell" ).GetSubkeyNames()]
        'PassThru'          = $True
    }
    $_ | Add-Member @Splat
} | Group Name | ForEach {
    [PSCustomObject]@{
        'Name'   = $_.Name
        'Bag'    = $_.Group.Bag
        'Type'   = $_.Group.Type | Select -Unique
    }

### *** Launch GridView for folder selection ***

} | Out-GridView -PassThru | ForEach{

### Confirm copy
    $Splat = @(
        $_.Type
        $_.Name
        $_.Bag
        ( Copy-Item -Path "$Bags\$($_.Bag)\Shell\*" -Destination "$Bags\AllFolders\Shell" -Recurse -Force -PassThru ).Name.Replace( 'HKEY_CURRENT_USER' , 'HKCU' )
    )
    Write-Output ( $ConfirmCopy -f $Splat )

### Apply to existing?
    If ( ( Read-Host 'Apply this template to any currenly saved views of the same type? (Y/N)' ) -match '^y') {
        Get-ChildItem $Bags -Recurse -Depth 2 |
          Where PSChildName -eq $Splat[3].Split('\')[-1] |
          Where Name -notMatch AllFolders |
        Remove-Item -Recurse -Force
    }
}

You'll be presented with a GridView control that lists saved SearchResults view and allows you to select the desired view(s) (only one default for each type): enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .