Skip to content

Instantly share code, notes, and snippets.

@maacpiash
Last active June 1, 2020 13:51
Show Gist options
  • Select an option

  • Save maacpiash/58b15a99658573b6c79aec4574fd2929 to your computer and use it in GitHub Desktop.

Select an option

Save maacpiash/58b15a99658573b6c79aec4574fd2929 to your computer and use it in GitHub Desktop.
Rename the folders exported by Sony PlayMemories app to YYYY-MM-DD format
import { readdirSync, renameSync } from 'fs'
const dirName = process.argv[2] ?? './'
// if the path to the folders is not to be specified,
// the script should be run from inside the folder.
readdirSync(dirName, { withFileTypes: true })
.filter(dir => dir.isDirectory())
.map(dir => {
const oldName = dir.name
if (oldName.includes('-')) {
const items = oldName.split('-') // MM-DD-YYYY
if (items.length === 3) {
const newName =
`${items[2]}-${items[0].padStart(2, '0')}-${items[1].padStart(2, '0')}`
renameSync(oldName, newName)
console.log(`${oldName} changed to ${newName}`)
} else {
console.log(`Skipped ${oldName}`)
}
} else {
console.log(`Skipped ${oldName}`)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment