Skip to content

Instantly share code, notes, and snippets.

@fawazahmed0
Last active April 25, 2023 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fawazahmed0/f798acfd4d6aced944b2cbacbeb40e97 to your computer and use it in GitHub Desktop.
Save fawazahmed0/f798acfd4d6aced944b2cbacbeb40e97 to your computer and use it in GitHub Desktop.
const fs = require('node:fs/promises')
const path = require('path')
let pathToDir = path.join(__dirname, 'src')
let pathToDest = path.join(__dirname, 'dst')
async function begin(){
await fs.mkdir(pathToDest, {recursive:true})
for(let fileName of (await fs.readdir(pathToDir)) ){
let pathToFile = path.join(pathToDir, fileName)
let statValue = await fs.stat(pathToFile)
await fs.copyFile(pathToFile, path.join(pathToDest, `${toISOLikeString(statValue.birthtime).replaceAll(':','-')}${fileName}`));
}
}
begin()
function toISOLikeString(dateObj) {
if (!(dateObj instanceof Date))
dateObj = new Date(dateObj)
return dateObj.toLocaleString("sv-SE", { timeZone: "Asia/Kolkata", dateStyle: 'short', timeStyle: "long" })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment