Last active
May 16, 2024 14:45
Rename image files to YYYYMMDD_HHMMSS format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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