Skip to content

Instantly share code, notes, and snippets.

@jarad
Last active May 16, 2024 14:45
Show Gist options
  • Save jarad/a5214c346a1282d141109ce06e5706e9 to your computer and use it in GitHub Desktop.
Save jarad/a5214c346a1282d141109ce06e5706e9 to your computer and use it in GitHub Desktop.
Rename image files to YYYYMMDD_HHMMSS format
# Rename image files using YYYYMMDD_HHMMSS in local time
# assumes your working directory is where the image files are
library("dplyr")
library("exifr")
library("lubridate")
filetype <- "HEIC"
old_names <- list.files(pattern = paste0("*.", filetype))
d <- read_exif(old_names) |>
mutate(
# Convert to date-time object
CreateDate = parse_date_time(CreateDate,
orders = "Y:m:d H:M:S",
tz = Sys.timezone()), # record in local timezone
# Create new filenames
new_prefix = format(CreateDate, format = "%Y%m%d_%H%M%S"),
new_filename = paste0(new_prefix, ".", filetype)
)
file.rename(d$FileName, d$new_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment