library(tidyverse)
library(lubridate)
library(magrittr)
library(rprojroot)
library("tidylog", warn.conflicts = FALSE)
library(reactable)
library(reactablefmtr)
library(exiftoolr)
library(grateful)
#configure_exiftoolr(command = "c:/windows/exiftool.exe")
#Local paths
base_path <- find_rstudio_root_file()
source_path <- file.path(base_path, "source_data//") # my folder is /source_data
# 2022-02-03 19:07:41 ------------------------------mdp
# 2022-02-07 20:49:09 ------------------------------mdp
Source file is generated by ExifTool from a batch file. Can be done from command line as well but easier to edit a batch file.
Here's the command - it needs to be in a single line. Watch the ">".
c:\windows\exiftool.exe -csv -common -r G:\\source_data\ >G:\\source_data\Castilleja.csv
I used the default installation for ExifTool so your path to exiftool.exe may be different. Your image folders will be different as well.
# Source file here is output from command line exiftool
Castilleja <- read_csv(paste0(source_path, "Castilleja.csv"))
reactable(Castilleja[1:6], highlight = TRUE, bordered = TRUE, striped = TRUE)
dilbert <- Castilleja %>% separate(SourceFile, c("drive","R", "project",
"source","imageSet", "junk"), sep = "/")
dilbert$junk <- NULL
dilbert$edited <- "edits"
reactable(dilbert[1:6], highlight = TRUE, bordered = TRUE, striped = TRUE)
dilbert <- dilbert %>% unite("inFilePath", 1:5, remove = FALSE, sep = "/") %>%
mutate("inFilePathName" = paste0(inFilePath, "/", FileName)) %>%
unite("editFilePath", inFilePath,
edited,
FileName,
sep = "/", remove = FALSE)
dilbert$inFilePath[1]
dilbert$inFilePathName[1]
dilbert$edited[1]
dilbert$editFilePath[1]
edits <- dilbert %>% filter(Model == "SM-G950U") %>%
select(-c(drive, R, project, source, imageSet, FileSize, Model, ImageSize, Quality, FocalLength, ShutterSpeed, Aperture, ISO, WhiteBalance, Flash))
reactable(edits[1:5,], highlight = TRUE, bordered = TRUE, striped = TRUE)
This is really just for grins and giggles - it isn't necessary
FromName <- edits$inFilePathName
ToName <- paste0(edits$editFilePath)
folder <- "source_data/Castilleja/edits"
if (file.exists(folder)) {
cat("The folder already exists")
} else {
dir.create(folder)
}
file.rename(FromName, ToName)
Exiftool creates a copy of the all the files and renames them prior to making any changes
Edits_df <- edits %>% mutate("newDateTime" = "5:0:11 0:0:0")
exif_call(args = Edits_df$editFilePath, paste0("-DateTimeOriginal+=", Edits_df$newDateTime))
dogbert <- exif_read(Edits_df$editFilePath) %>%
select(FileName, Model, ModifyDate, DateTimeOriginal)
reactable(dogbert, highlight = TRUE, bordered = TRUE, striped = TRUE) %>%
add_title("FileName & ModifyDate are the same") %>%
add_subtitle("We added 5 years 11 days to DateTimeOriginal") %>%
add_source("We should have paid closer attention - the date on the first file doesn't line up with the rest")
cite <- cite_packages(cite.tidyverse = TRUE, output="paragraph")
#cite <- get_citations(scan_packages())
cite