Created
November 18, 2020 20:21
-
-
Save kirbee/a6673cf10f132683152a6a02dda21263 to your computer and use it in GitHub Desktop.
A quick node script I used to re-organize some documents in the way I wanted them before uploading them to Google Drive
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 testFolder = './'; // to be run in the directory with all files we are looking to move | |
const fs = require('fs'); | |
fs.readdirSync(testFolder).forEach((file) => { | |
const regex = /SL([0-9]*) Unit([0-9]*) ([0-9\.]*)/; // eg "SL001 Unit403 2005.11.30.pdf" | |
const test = regex.exec(file); | |
if (test) { | |
const sl = test[1]; // First matching group | |
const unit = test[2]; // Second matching group | |
const date = test[3]; | |
const dateHyphen = date.split('.').join('-').slice(0, -1); | |
// Dirname "403 - SL001/Assignment Forms" | |
const foldername = `${unit} - SL${sl}/Assignment Forms`; | |
// Filename "403 - SL001/Assignment Forms/Assignment Form 2005-11-30" | |
const filename = `${foldername}/Assignment Form ${dateHyphen}`; | |
// Uncomment to run, make sure to test first! | |
// fs.mkdirSync(foldername, { recursive: true }); | |
// fs.renameSync(file, filename); | |
console.log(filename); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, it's ugly ... but it works (and it's better than manually creating every folder and drag/dropping :puke: