Hello,
I am very new in R and still learning main concepts. This is my first message here I hope I didn't post it in the wrong place.
I am trying to create a piece of code to:
- Read image file names(and path) from a folder
- Extract selected EXIF fields of these images into a table.
- Save resulting CSV table to a folder (with column names, if it doesn't exist).
- On next run, read files from images folder, and add only the newly added files to above table, this time without column names, naturally).
I have tried something below, but no idea about possible pitfalls.
Ideally this should run whenever a new file added and, should record to a database table instead of CSV, but, this is something to start with..
I really appreciate if someone investigates the following code and indicate failure causes,
Thanks in advance,
> setwd("D:/Users/user/Pictures/2011-01-10")
>
> library(data.table)
> library(dplyr)
> library(exifr)
>
> f <- paste0(getwd(),"/","exifdata",".csv")
> if (!file.exists(f))
> {
> image_files <- list.files(path = ".", pattern=".JPG", full.names = TRUE)
>
> current_image_list <- read_exif(image_files, tags = c("Make"))
>
> write.table(current_image_list, "exifdata.csv", sep = ",", row.names=FALSE, col.names = T, append = F)
> }
>
> mainimagelist <- read.table("exifdata.csv", header = T, sep = ",")
>
> image_files <- list.files(path = ".", pattern=".JPG", full.names = TRUE)
>
> current_image_list <- read_exif(image_files, tags = c("Make"))
>
> rownames(current_image_list) <- c()
>
> finalimagelist <- rbind(setDT(mainimagelist), setDT(current_image_list))
>
> finalimagelist <- distinct(finalimagelist)
>
> write.table(finalimagelist, "exifdata.csv", sep = ",", row.names = F, col.names = F, append = T)
´´´