Last active
December 22, 2024 17:04
-
-
Save Rankarusu/29f7637a29c06176e7b0b5e440f76cbf to your computer and use it in GitHub Desktop.
Update file modified date according to name
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
const { execSync } = require("child_process"); | |
const fs = require("fs"); | |
const pattern = /\D{3}_(\d{8})_.*/; | |
fs.readdir("./", (err, files) => { | |
files.forEach((file) => { | |
const match = pattern.exec(file); | |
const yyyymmdd = match?.[1]; | |
if (yyyymmdd) { | |
const output = execSync(`touch -d ${yyyymmdd} -f ${file}`, { encoding: "utf-8" }); | |
if (output) { | |
console.log(output); | |
return; | |
} else { | |
console.log(`Processed ${file}`); | |
} | |
} else { | |
console.log(`Skipped file ${file}`); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment