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"))
Much appreciated for help! I'm an undergrad and experience experienced issues making papers and another made work. That is the explanation bestessay, it saves individual time I really have splendid school execution and a high GPA. All works without duplicating and on time
Thanks for that useful information, Justin. I've been using RichCopy for years and never noticed that it copies the Date Created time stamp by default. (The option to turn the feature on/off is buried in the "File attributes / Error Handling" section).
It should be blindingly obvious but - for anyone else who is as dim as I was - the "Created" time is when the file was opened on the AudioMoth ie at the start of the recording and the "Modified" time corresponds to when the file was closed at the end.
"Ordinary" Windows Copy writes a new Created time stamp but retains the original Modified stamp whereas RichCopy retains or re-writes both timestamps together, depending upon your selected option, and can also re-write them both to a specified date/time of your choosing.
One feature to beware of (again it should be obvious) is that if you set RichCopy to copy several files in parallel (increasing the copying speed) the resulting copied files are likely to be highly fragmented, which may or may not be a problem.
Opps - forgot the link... https://technet.microsoft.com/en-us/library/2009.04.utilityspotlight.aspx
Peripherally relevant, but possibly useful too - There is a handy utility from Microsoft which will copy or move files while keeping all the timestamps intact. It also uses multi-threading to copy several files at once speeding things up, and can recover an interrupted copy session.
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.
Bulk Rename Utility can also correct the UTC timestamps to local time if that is your preference.
Or you can just use Bulk Rename Utility to rename the files incorporating the creation/modified dates and times, plus any additional info.
Forgot to copy the result in previous post. Here it is:
String in ISO format: 2018-03-17T15:52:20Z String in compact ISO format: 20180317T155220Z String if you are using pandas: 2018-03-17 15:52:20
This is the core part if you like Python:
import pathlib
import datetime
import pandas
file_name = '5AAD39B4.WAV'
file_stem = pathlib.Path(file_name).stem
posix_time = int(file_stem, 16)
print('String in ISO format: ',
datetime.datetime.utcfromtimestamp(posix_time).strftime('%Y-%m-%dT%H:%M:%SZ'))
print('String in compact ISO format: ',
datetime.datetime.utcfromtimestamp(posix_time).strftime('%Y%m%dT%H%M%SZ'))
print('String if you are using pandas:',
pandas.to_datetime(posix_time,unit='s'))
You can also convert a folder of AudioMoth filenames to date/time format using a hybrid jscript/batch utility called JREN, written by Dave Benham.
The latest version of the code is available from GitHub at https://github.com/swingflip/Hakchi-Extra-Tools/blob/master/JREN.bat with Dave's notes from an earlier version at www.dostips.com/forum/viewtopic.php?t=6081
Copy the code into a text file and rename it to JREN.BAT then run it from a command window in the folder containing the files you wish to rename using the syntax:
jren "^([0-9A-F]{8})\.wav$" "ts({dt:('0x'+$1)*1000,tz:60,fmt:'{iso-dt}_{hh}-{nn}-{ss}.wav'})" /j /i
Note that the option "tz:60" defines timezone +60 minutes to convert UTC/GMT to BST - modify as necessary for your current timezone.
Best plan is to call JREN with the appropriate arguments (as above|) from a second batch file (eg jren_am.bat) and save both batch files in a folder somewhere on your Path (I put them in the C:\Windows folder). Then all you need to do is open a cmd window in the folder containing your files and run "jren_am" and all the filenames will be converted.
Another option is to use the free program Advanced Renamer from www.advancedrenamer.com, which will allow you to rename your files based on the date & time from the "Date Modified" tag (which includes seconds that are suppressed by Windows Explorer). However, whilst the AudioMoth Unix Epoch filename corresponds to the start of the recording, the "Date Modified" time appears to correspond to the time that the file was saved to the SD card at the end of the recording.