Last active
April 20, 2021 16:35
-
-
Save ersgonzalo/b4992c2cbcec0d43222ef628b25ad02f to your computer and use it in GitHub Desktop.
Unix Time File Renaming from Arlo Video Downloads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Note that this is a node.js script so you will also have to `npm install moment` | |
const fs = require('fs'); | |
const moment = require('moment'); | |
const { resolve, sep } = require('path'); | |
//Replace the {yourFolderDirectoryHere} with the directory of Unix files you want to rename | |
const testFolder = './{yourFolderDirectoryHere}/'; | |
const fileDirPath = resolve(__dirname, testFolder); | |
fs.readdir(testFolder, (err, files) => { | |
//Read in the list of files in the folder above | |
files.forEach(renameFile); | |
}); | |
const renameFile = function(passedFile){ | |
let newFileName = fileDirPath + sep + renameToLocalTimezone(passedFile); | |
let oldFileName = fileDirPath + sep + passedFile; | |
// Filename will have Unix Time | |
return fs.rename(oldFileName, newFileName, (err)=>{ | |
console.log(err); | |
}); | |
}; | |
const renameToLocalTimezone = function (unixTimeFileToConvert){ | |
let fileToRename = unixTimeFileToConvert.split('.'); | |
let unixValue = parseInt(fileToRename[0]); | |
unixValue = moment(unixValue).local().format('YYYY-MM-DD HH.mm.ss'); | |
fileToRename[0] = unixValue; | |
return fileToRename.join('.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment