Quantcast
Channel: DEVONtechnologies Community - Latest posts
Viewing all articles
Browse latest Browse all 17691

Unable to extract date from file name

$
0
0

Hello There,
I’me trying for 3 hours to extract date from file name.
I’ve read 10 thread about this.
I’ve tried using chatgpt.
Unable to understand if my problem comes from localisation or whaever.
Unable to understand if there is many different date for the same file.

My goal is to convert part of file name in “creation date” (ideally) or at least in “date of personnal meta data”.

When asking many many script to ChatGPT unable to correct it :

tell application "DEVONthink 3"
    set theRecords to (every record of current database whose type is "file")
    
    repeat with theRecord in theRecords
        set theName to name of theRecord
        set theDate to extract date from theName
        if theDate is not missing value then
            set creation date of theRecord to theDate
        end if
    end repeat
end tell

on extract date from theName
    set dateString to ""
    set dateRegex to "(?<=-\\s)\\d{8}(?=\\s-)"
    try
        set dateString to do shell script "echo " & quoted form of theName & " | grep -Eo " & quoted form of dateRegex
    end try
    if dateString is not "" then
        set yearPart to text 1 thru 4 of dateString
        set monthPart to text 5 thru 6 of dateString
        set dayPart to text 7 thru 8 of dateString
        set theDate to date (yearPart & "-" & monthPart & "-" & dayPart)
        return theDate
    else
        return missing value
    end if
end extract date

About date I have some other questions :

What are the differences between création date from finder, creation date from DT point of view?

Any help much appreciated. I have the last 3.000+ files date to extract. :slight_smile:


Viewing all articles
Browse latest Browse all 17691

Trending Articles