Hi all,
Not sure if someone has done this here already, but I've created some R code to batch rename a folder of AudioMoth files to apply the date and time they were created. Hope this is of use to others:
#Convert filenames of AudioMoth to date and time of creation
library(tidyverse)
#Set directory to folder containing files
setwd("~/Dropbox (Baker Consultants)/AudioMoth_Rename") #Change this to wherever your files are located
Audiomoth_Dir <- "~/Dropbox/AudioMoth_Rename"
#Generate list of files present within the folder
file_list <-list.files(Audiomoth_Dir, pattern = "*.WAV", full.names = FALSE)
#Generate vector of creation dates and times
wav_file_info <- file.info(file_list)
new_names <- as.character(wav_file_info$mtime)
#Rename files
file.rename(from = file_list, to = str_c(new_names,".wav"))
You need to be aware that the AudioMoth sets the "Date modified" time to the END of each recording period, whereas the hexadecimal filename (UNIX epoch = seconds since midnight on 1st January 1970) corresponds to the START of the recording. Obviously the difference will be increasingly significant for longer recording times. Additionally the (Windows) "Date created" is set to the time that the file is copied to the PC and not related in any way to the time of recording.
The easiest way of converting UNIX filenames that I have found so far (in Windows) is to use a script in "Advanced Renamer": www.advancedrenamer.com
To convert UNIX epochs to local dates & times in the format "18-09-09_20-21-40.WAV", select "Script" from the "Add method" menu and paste in the following JavaScript code:
dat = new Date(1000 * parseInt(item.newBasename, 16));
return dat.getFullYear().toString().substr(-2)
+ "-" + ("0" + (dat.getMonth() + 1)).slice(-2)
+ "-" + ("0" + dat.getDate()).slice(-2)
+ "_" + ("0" + dat.getHours()).slice(-2)
+ "-" + ("0" + dat.getMinutes()).slice(-2)
+ "-" + ("0" + dat.getSeconds()).slice(-2);
If you prefer to keep times in UTC (GMT) then simply replace all the .get... methods with .getUTC... (eg dat.getUTCFullYear() etc). You can save the "Method list" so that the script can be reloaded from the "Presets" dropdown box without having to enter it again.
The only issue is that hours are returned in the range 0-23, so that midnight is 00-00-00 rather than 24-00-00 on the previous day.