Set file created/modified timestamp to the earlier of the 2 for a ton of files? I searched for an answer to this for a while, but couldn't find one. I have a lot of wav files (thousands of them) in a sound library that somehow got either the modification or creation date updated very recently, even though I haven't touched them in any way for years.
Is there some way I could use Automator to make an application that I could drag &amp; drop these files to (or a text file containing all of their paths &amp; filenames) that would do the following?:

Check the timestamp data associated with the file
(date/time: modified, and created)
Check to see which timestamp is the earlier of the two
If the created timestamp is earlier than the modified one, change the modified timestamp to the created, or vice versa.

I know how to get the date modified or created in terminal, and how to loop through the files received as input. But I'm not sure how to compare the timestamps in a script to determine which is earlier, or how specifically to format the script/app that would do this automatically for each file.
I got the following script from another thread. But this will just set the date modified to the date created without checking to see which one is earlier.
for f in *.wav; do
   olddate=$(stat -f %SB -t %Y%m%d%H%M &quot;$f&quot;)
   touch -m -t $olddate &quot;$f&quot;    
done

And in case it makes a difference, I'm on a MacBook Pro running macOS Sierra 10.12.6.
Lastly, if this would be more appropriate for a different network (stackoverflow or superuser maybe), please LMK and I'll ask there instead.
Thank you in advance for the help!
The example shell script code, show below, uses GetFileInfo and SetFile from Command Line Tools for Xcode, which the latter is needed to change the creation date, as touch can only change the access and modification times.
If you do not have Xcode installed, then just install the Command Line Tools for Xcode...
In Terminal: xcode-select --install
After installing Command Line Tools for Xcode, then in Automator you can create a workflow or Service/Quick Action with the appropriate actions to pass the target files to a Run Shell Script action with settings Shell: [/bin/bash] and Pass input: [as arguments] using the following example shell script code:
for f in &quot;$@&quot;; do

    [ -f &quot;$f&quot; ] || continue

    c=&quot;$(GetFileInfo -d &quot;$f&quot;)&quot;
    m=&quot;$(GetFileInfo -m &quot;$f&quot;)&quot;

    ec=&quot;$(date -j -f &quot;%m/%d/%Y %H:%M:%S&quot; &quot;$c&quot; +%s)&quot;
    em=&quot;$(date -j -f &quot;%m/%d/%Y %H:%M:%S&quot; &quot;$m&quot; +%s)&quot;

    if [ &quot;$ec&quot; -lt &quot;$em&quot; ]; then
        SetFile -m &quot;$c&quot; &quot;$f&quot;
    fi

    if [ &quot;$em&quot; -lt &quot;$ec&quot; ]; then
        SetFile -d &quot;$m&quot; &quot;$f&quot;
    fi

done


How the shell script works:

for f in &quot;$@&quot;; do -- For each file do something.
[ -f &quot;$f&quot; ] || continue -- If it's not a file, then go to the next item passed.
c=&quot;$(GetFileInfo -d &quot;$f&quot;)&quot; -- Gets the creation date of the file.
m=&quot;$(GetFileInfo -m &quot;$f&quot;)&quot; -- Gets the modification date of the file.
ec=&quot;$(date -j -f &quot;%m/%d/%Y %H:%M:%S&quot; &quot;$c&quot; +%s)&quot; -- Converts the creation date to the number seconds since Epoch.
em=&quot;$(date -j -f &quot;%m/%d/%Y %H:%M:%S&quot; &quot;$m&quot; +%s)&quot; -- Converts the modification date to the number seconds since Epoch.
if [ &quot;$ec&quot; -lt &quot;$em&quot; ]; then -- If the Epoch creation date seconds is less than the Epoch modification date seconds, then:

SetFile -m &quot;$c&quot; &quot;$f&quot; -- Sets the modification date of the file to the creation date of the file.


if [ &quot;$em&quot; -lt &quot;$ec&quot; ]; then -- If the Epoch modification date seconds is less than the Epoch creation date seconds, then:

SetFile -d &quot;$m&quot; &quot;$f&quot; -- Sets the creation date of the file to the modification date of the file.




Notes:
Epoch (00:00:00 UTC, January 1, 1970; see time(3).


Example Automator workflow:
Just add the parent folder containing the .wav files to the Get Specified Finder Items action and the rest of the actions.
Note that this is just an example, the main part is the Run Shell Script action, so however you want to pass the target files to it is your choice.