Match the Creation Date of 2 sets of files with same name

command line

I've just converted hundreds of AIF recordings from a few days ago to WAV, but I need the newly created files to keep the original Creation Date of the recordings. Filenames are identical apart from the extension, stored in two separate folders.

Is there a way to batch modify each WAV's Creation Date to match its respective AIF?

Thanks!

Best Answer

Assuming a folder structure like

./
+--AIFFolder/
+--WAVFolder/

and also assuming that the WAV files end in .wav you can use

cd AIFFolder
for f in *; do
    date=$(stat -f %SB -t %Y%m%d%H%M "$f")
    base=${f%.*}
    touch -t $date ../WAVFolder/"$base".wav
done

This can be simplified (thanks for the hint, @fd0) to

cd AIFFolder
for f in *; do
    touch -r "$f" ../WAVFolder/"${f%.*}.wav"
done