SHARE
TWEET

Untitled

a guest Sep 17th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs')
  2.  
  3. const re = /(\d+)\s(\w+)\s(\d+)/
  4. const months = {
  5.   January: '01',
  6.   February: '02',
  7.   March: '03',
  8.   April: '04',
  9.   May: '05',
  10.   June: '06',
  11.   July: '07',
  12.   August: '08',
  13.   September: '09',
  14.   October: '10',
  15.   November: '11',
  16.   December: '12',
  17. }
  18.  
  19. const folders = fs.readdirSync('.').filter(folder => {
  20.   const meta = folder.split(',').map(f => f.trim())
  21.   return re.test(meta[meta.length - 1])
  22. })
  23.  
  24. folders.forEach(folder => {
  25.   let [date, place, location] = folder
  26.     .split(',')
  27.     .reverse()
  28.     .map(f => f.trim())
  29.   const [, day, month, year] = re.exec(date)
  30.   const formatted = [
  31.     `${year}-${months[month]}-${('0' + day).slice(-2)}`,
  32.     place,
  33.     location,
  34.   ]
  35.     .filter(d => !!d)
  36.     .join(', ')
  37.  
  38.   fs.renameSync(folder, formatted)
  39. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top