Hello,
I wrote a bash script that should set or change the "CreateDate" parameter. Unfortunately, reading, displaying and selecting the file works. Unfortunately, writing the "CreateDate" does not work.
Does anyone have any advice for me as to what could be causing this?
Thank you!
tony
#!/bin/bash
# Erstelle ein Array mit allen Dateien im aktuellen Unterverzeichnis
files=(*)
# Erstelle eine temporäre Datei, um die Dateiinformationen zu speichern
tmpfile=$(mktemp)
# Schreibe die Dateiinformationen in die temporäre Datei
for file in "${files[@]}"; do
# Extrahiere den Dateinamen, das Speicherdatum, die Speicheruhrzeit und das CreateDate mit exiftool
filename="$file"
savedate=$(exiftool -d "%Y-%m-%d" -p '$FileModifyDate' "$file")
savetime=$(exiftool -d "%H:%M:%S" -p '$FileModifyDate' "$file")
createdate=$(exiftool -d "%Y-%m-%d %H:%M:%S" -p '$CreateDate' "$file")
# Schreibe die Informationen in die temporäre Datei, getrennt durch Kommas
echo "$filename,$savedate,$savetime,$createdate" >> "$tmpfile"
done
# Sortiere die temporäre Datei nach dem CreateDate in aufsteigender Reihenfolge
sort -t "," -k 4 "$tmpfile" > "${tmpfile}.sorted"
# Lösche die ursprüngliche temporäre Datei
rm "$tmpfile"
# Zeige die sortierten Dateiinformationen an
echo "Dateiname | Speicherdatum | Speicheruhrzeit | CreateDate"
cat "${tmpfile}.sorted" | awk -F "," '{print $1 " | " $2 " | " $3 " | " $4}'
# Erstelle ein Auswahlmenü, um einzelne Dateien auszuwählen und das CreateDate zu ändern
PS3="Wählen Sie eine Datei aus oder drücken Sie q, um das Skript zu beenden: "
select file in "${files[@]}"; do
# Beende das Skript, wenn q gedrückt wird
if [[ "$REPLY" == "q" ]]; then
break
fi
# Überprüfe, ob eine gültige Datei ausgewählt wurde
if [[ -n "$file" ]]; then
# Zeige das aktuelle CreateDate der ausgewählten Datei an
echo "Die ausgewählte Datei ist $file"
echo "Das aktuelle CreateDate ist $(exiftool -d "%Y-%m-%d %H:%M:%S" -p '$CreateDate' "$file")"
# Frage nach dem neuen CreateDate im Format YYYY-MM-DD hh:mm:ss
read -p "Geben Sie das neue CreateDate im Format YYYY-MM-DD hh:mm:ss ein: " newdate
# Überprüfe, ob das neue CreateDate gültig ist
if [[ "$newdate" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}$ ]]; then
# Ändere das CreateDate der ausgewählten Datei mit exiftool
exiftool "-CreateDate=$newdate" "$file"
# Zeige eine Erfolgsmeldung an
echo "Das CreateDate von $file wurde erfolgreich auf $newdate geändert."
else
# Zeige eine Fehlermeldung an, wenn das neue CreateDate ungültig ist
echo "Das eingegebene Datum ist ungültig. Bitte versuchen Sie es erneut."
fi
else
# Zeige eine Fehlermeldung an, wenn keine gültige Datei ausgewählt wurde
echo "Ungültige Auswahl. Bitte wählen Sie eine gültige Datei aus."
fi
done
# Lösche die temporäre Datei mit den sortierten Informationen
~
Sorry, I can't really help as I'm a Windows user.
Can you capture the output from the exiftool command? It's hard to trouble shoot an issue without known why it's failing. And if the problem is actually with exiftool, it should be returning a reason why it failed.
Other than that, use basic debugging techniques. Lots of print statements showing the variable values at each step. Comment out everything and add things line by line until you figure out where the problem is.
Can you echo the exact exiftool command that you are using to write CreateDate, then try it at the console to see what messages ExifTool gives you? We should be able to help more if you tell us what this command was.
- Phil