2

I have a folder full of recordings which all read: " rec.(unixtime).mp3 "

ex: "rec.1447666687584.mp3" ideally turns into something like "10-16-2015_01-38-07.mp3"

I need to convert these filenames pretty regularly so I'm assuming writing a bat file is the best way to do this.

it seems easy enough to remove the first three characters as seen over here How can I remove the first character from all filenames in a folder?

and the mathematics for converting from epoch to days seems straightfoward as well ((((epochtimevalue/1000)/60)/60)/24) + the date 1/1/1970.

Does anyone have a straightforward solution for converting filenames like this?

2
  • Your math is wrong. You don't say what time zone you are in, but the GMT value for that epoch time is 11-16-2015_04-38-07.
    – dbenham
    Jan 17, 2016 at 5:32
  • Doh! - my mistake. I accidentally posted the U.S. Eastern standard time (GMT - 5:00) equivalent. The GMT time is 11-16-2015_09-38-07
    – dbenham
    Jan 17, 2016 at 5:50

1 Answer 1

1

My JREN.BAT regular expression renaming utility is perfect for this problem. It is pure script (hybrid JScript/batch) that runs natively on any Windows machine from XP onward. Full documentation is built into the script, and can be reached by executing jren /? (or jren /?? if you want paged help).

JREN.BAT allows you to match and rename files using regular expressions, and the replacement string can be a JScript expression. Built into the utility is a sophisticated timestamp formatting function that makes the job really easy.

The following one liner will rename all "rec.EpochTime.mp3" files in the current directory to
"MM-DD-YYYY_hh-mm-ss.mp3" format. It will convert the epoch time using your local time zone. There are additional options that allow you to specify a specific time zone for the output.

jren "^rec\.(\d+)\.mp3$" "ts({dt:$1,fmt:'{mm}-{dd}-{yyyy}_{hh}-{nn}-{ss}.mp3'})" /j

But I strongly advise that you change the date format from MM-DD-YYYY to YYYY-MM-DD instead. This allows you to easily sort your directory listings chronologically. The {iso-dt} format is shorthand for {yyyy}-{mm}-{dd}.

jren "^rec\.(\d+)\.mp3$" "ts({dt:$1,fmt:'{iso-dt}_{hh}-{nn}-{ss}.mp3'})" /j

Given that JREN is itself a batch script, you should use CALL JREN if you put the command within another batch script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .