Sorting folders numerically

I use CM on my PC and Android and I just discovered this small issue. I am wondering if anyone has an opinion.
I name my folders like this:
2024.1.18
2024.2.18
2024.3.18
2024.4.18
2024.5.18
2024.6.18
2024.7.18
2024.8.18
2024.9.18
2024.10.18
2024.11.18
2024.12.18
However, CM does not list them like this. Everything is ok from 2024.1.18 until 2024.9.18.
But the months of 10, 11, and 12 do not appear after month 9 as shown above.
10, 11, 12 (ie Oct, Nov and Dec) are listed after Jan. So it look like this:
2024.1.18
2024.10.18
2024.11.18
2024.12.18
2024.2.18
This doesn’t make sense to me.
This only happens on ANDROID. File Explorer sorts them properly.
I know this isn’t the end of the world but is there any way to fix this?

Hi,

On Android, which cloud provider are you using?

I Might have a workaround, but I need to test it first.

Update:

I created a list of all of the same folders that you have on my pcloud drive and accessed from my Android phone and it did not matter whether I used Cryptomator or not.

The pcloud drive client for Android lists the files in the same order as other file managers do on Android I’ve tried three programs and they all list files out differently than they do on Windows.

It looks like all Android file managers are going to list the folders in an order that you don’t want them in and I don’t see a way to change it.

The proper naming would be to include the leading zero for the months, like 07, 08, 09.

Have you tried:
2024.01.18
2024.02.18
2024.03.18
2024.04.18
2024.05.18
2024.06.18
2024.07.18
2024.08.18
2024.09.18
2024.10.18
2024.11.18
2024.12.18
or is it too late to rename those folders? If not too late, this could save you a lot of unexpected headaches.

1 Like

@Rcmtr @Funkhauser

That works!!

1 Like

Thank you Rcmtr and LeoW!
That works!!!
I should have thought of that. When I was with Boxcryptor this wasnt’t an issue.
Not sure why that is but you have solved my issue.

2 Likes

import os
import re

def rename_files_with_date_format(directory):
# Regex to match date formats like “2024.1.18”
date_pattern = re.compile(r’(\d{4}).(\d{1,2}).(\d{1,2})')

# Iterate through all files in the directory
for filename in os.listdir(directory):
    # Search for the date format in the filename
    match = date_pattern.search(filename)
    
    if match:
        # Extract year, month, and day, and add leading zeros
        year = match.group(1)
        month = match.group(2).zfill(2)
        day = match.group(3).zfill(2)
        
        # New filename with leading zeros
        new_filename = date_pattern.sub(f"{year}.{month}.{day}", filename)
        
        # Rename the file
        old_file_path = os.path.join(directory, filename)
        new_file_path = os.path.join(directory, new_filename)
        
        os.rename(old_file_path, new_file_path)
        print(f"Renamed: {filename} -> {new_filename}")

Specify the directory path

directory = ‘YOUR/PATH/TO/DIRECTORY’
rename_files_with_date_format(directory)

import os
import re

def rename_files_with_date_format(directory):
    # Regex to match date formats like "2024.1.18"
    date_pattern = re.compile(r'(\d{4})\.(\d{1,2})\.(\d{1,2})')
    
    # Iterate through all files in the directory
    for filename in os.listdir(directory):
        # Search for the date format in the filename
        match = date_pattern.search(filename)
        
        if match:
            # Extract year, month, and day, and add leading zeros
            year = match.group(1)
            month = match.group(2).zfill(2)
            day = match.group(3).zfill(2)
            
            # New filename with leading zeros
            new_filename = date_pattern.sub(f"{year}.{month}.{day}", filename)
            
            # Rename the file
            old_file_path = os.path.join(directory, filename)
            new_file_path = os.path.join(directory, new_filename)
            
            os.rename(old_file_path, new_file_path)
            print(f"Renamed: {filename} -> {new_filename}")

# Specify the directory path
directory = 'YOUR/PATH/TO/DIRECTORY'
rename_files_with_date_format(directory)

Hello!
This is an old problem from the 80s.
Sorting is done from left to right, characters or numbers according to the ASCII code. Sorting is by position in the ASCII table

(the dot) . = character no. 46
(zero) 0 = Character no. 48
(one) 1 = Character no. 49

Sorted by position in the ASCII table

Write instead of 2024.1.18 = 2024.01.18
And your problem is solved.

:::: ASCII - Wikipedia