Last active
April 25, 2023 07:15
-
-
Save fawazahmed0/f798acfd4d6aced944b2cbacbeb40e97 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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