Last active
June 1, 2020 13:51
-
-
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
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
| 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