Search code examples
windowsexplorer

How to get Windows File Explorer to sort in alphanumeric order of filename


This is a question about the Windows Explorer sorted order. It seems a basic question but I have not found an answer. Here I use Python to show the correct order and a screenshot to show the Windows 11 order. Windows is parsing the name and treating a sequence of digits as a single value. My question is how to configure Widows to display the names in the expected order?

import os
direc = './test/'
if not os.path.isdir(direc):
    os.makedirs(direc)
files = ['a02.txt', 'a3a.txt', 'a03.txt', 'a04.txt', 'a2a.txt']
for file in files:
    open(direc+file, 'a')
for filename in os.listdir(direc):
    print(filename)

Result (as expected):

a02.txt
a03.txt
a04.txt
a2a.txt
a3a.txt

Screenshot of Windows 11 File Explorer:

Screenshot of Windows 11 File Explorer


Solution

  • You can try disabling "numerical sorting" like this

    • regedit.exe
    • Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer
    • Create a DWORD 32-bit entry with name NoStrCmpLogical and set value to 1
    • Restart