Skip to content

Instantly share code, notes, and snippets.

@atao
Created September 23, 2024 19:02
Show Gist options
  • Save atao/dabac99fe09c04eebb90453bcfbfd75f to your computer and use it in GitHub Desktop.
Save atao/dabac99fe09c04eebb90453bcfbfd75f to your computer and use it in GitHub Desktop.
Rename my Spypoint pictures
#!/bin/bash
# Check if a directory has been provided as an argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 path_to_directory"
exit 1
fi
directory="$1"
# Check if the directory exists
if [ ! -d "$directory" ]; then
echo "The directory '$directory' does not exist."
exit 1
fi
# Loop through all files in the directory
for file in "$directory"/*; do
# Check if it is a file
if [ -f "$file" ]; then
# Get the last modification date and time of the file (format: YYYY-MM-DD_HH-MM)
mod_time=$(stat -c %Y "$file")
formatted_time=$(date -d @"$mod_time" +"%Y-%m-%d_%H-%M-%S")
# Rename the file
filename=$(basename "$file")
new_name="$directory/${formatted_time}_$filename"
mv "$file" "$new_name"
echo "The file '$filename' has been renamed to '${formatted_time}_$filename'."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment