Filename correct sorting

Hey I have a lot of documents in one folder in Devonthink. How can I setup the filename that the files are sorted correctly
Filenames are currently like this MM/YYYY-Apo_Rezept
for example 07/2023-Apo_Rezept
and of course the sorting of the folder should be like this
01/2023-Apo_Rezept
02/2023-Apo_Rezept
03/2023-Apo_Rezept

01/2024-Apo_Rezept
02/2024-Apo_Rezept

But instead I get a sorting like this

01/2023-Apo_Rezept
01/2024-Apo_Rezept
02/2023-Apo_Rezept
02/2024-Apo_Rezept

Update:
ok the sorting of the filenames are now working thanks to @DTLow
Now as a second step can I change the file creation date now from the filename itself?
for example filename is 2024/02-Apo_Rezept and I want to set the file creation date to 01.02.2024?
I tried to do this with a smart rule but If I read the expression with ([0-9]{4})/([0-9]{2})
and then want to change the creation date Devonthink doesn’t give me the option to enter a regex expression ? How could I achieve this?

Change your date format to YYYY/MM
I use “-“ as the delimiter ( ISO 8601)

3 Likes

thanks that has worked out

Where are you getting the 01 in 01.02.2024 from? Just hardcoding the first of the month?

yes the important fing for me is just the month and the year in the creation date. that’s why I set the date to the 1st which is fine

This isn’t going to be accomplished without an Apply Script smart action or a standalone script, especially as there is no detectable full date in the filename.

PS: I would recommend not using forward slashes as those mean something in DEVONthink and the filesystem.

2 Likes

ok thanks for your support BTW.

what do you suggest to use for filenames with dates instead then? a backslash? or a “-” ?
regarding changing the doc creation date if I create an Applescript for that what is the variable name for the date creation date ? how can I adresse it within an apple script?

You’re welcome :slight_smile:
I recommend a dot.

Here is a script for the Apply Script smart action…

on performSmartRule(theRecords)
	set od to AppleScript's text item delimiters
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set recName to (name without extension of theRecord)
			set AppleScript's text item delimiters to "_" -- Split on the underscore. 
			set {dateComponents, remainderOfName} to {item 1, items 2 thru -1} of text items of recName -- Split the name into date and name parts
			set AppleScript's text item delimiters to "/" -- Split the date with forward slashes
			set {y, m} to {item 1, item 2} of text items of dateComponents -- Get the year and month as variables
			set AppleScript's text item delimiters to "." -- This exchanges the forward slash for a dot.
			set creation date of theRecord to ({"01", m, y} as string) -- Set the date. This depends on your locale. In the US, 01.04.2024 is January 4, 2024 so they would use {m,"01",y}
			set dateString to {y, m, "01"} as string -- For use in the filename.
			set AppleScript's text item delimiters to "_"
			set name of theRecord to {dateString, remainderOfName} as string -- Modify the name to avoid slash collisions.
			set AppleScript's text item delimiters to od -- Reset the text item delimiter
		end repeat
	end tell
end performSmartRule

Updated the script for better preservation of underscores in the remainder of the name.

image

image

1 Like

ok thanks for that
there are 2 issues after running this script
for example before running the script the filename was
2017/12-Apo_Rezept
after running the script the filename was
2017.12-Apo.01_Rezept (there is 01 added to the filename which is not needed) I just need the month and the year in the filename
and for the file creation date the month and the day are switched. it is 12.01.2017 instead of 01.12.2017

I would dissuade you from this perspective. It is not a complete date and infringes on future automations. Since the 01 is essentially a placeholder, it should have no detrimental effect.

As an example…
image
… has a properly parseable date, yielding this…

This does not…
image

and for the file creation date the month and the day are switched. it is 12.01.2017 instead of 01.12.2017

See the note in the script regarding locale. You can easily change the order as you need to.

2 Likes

Thanks I have done it with your help

Thanks again very much really appreciate it

1 Like

You’re welcome :slight_smile:

1 Like

This made me twitch too. Solid suggestion.

2 Likes

Glad it was useful to you :slight_smile: