Skip to content

Instantly share code, notes, and snippets.

@shieva
Created February 4, 2018 03:26
Embed
What would you like to do?
change timestamp of files in nodejs
const moment = require('moment');
const fs = require('fs');
var Utimes = require('@ronomon/utimes');
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const folder = '100';
const files = fs.readdirSync(folder);
// console.log(files)
async function changeTimestamp() {
for (const index in files) {
const file = files[index];
// await sleep(1000);
let btime = + new Date();
btime += (index * 60000) + 48000000;
// const btime = moment().add(index, 'mins').unix();
Utimes.utimes(`${folder}/${file}`, btime, btime, btime, (err) => {
console.log('err', err)
console.log(`${folder}/${file}`);
});
}
}
changeTimestamp();
@kamel3d
Copy link

kamel3d commented Aug 24, 2019

the module @ronomon/utimes is not working on newer versions on node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment