Skip to content

Instantly share code, notes, and snippets.

@kambara kambara/howm2memolife.js
Last active Jul 16, 2018

Embed
What would you like to do?
const fs = require('fs')
const path = require('path')
const howmDir = '/Users/kambara/Desktop/howm'
const memoDir = '/Users/kambara/Desktop/memo'
function main() {
if (!fs.existsSync(memoDir)) {
fs.mkdirSync(memoDir)
}
fs.readdirSync(howmDir)
.filter(entry => entry.match(/^\d{4}$/))
.map(year => path.join(howmDir, year))
.filter(yearPath => fs.statSync(yearPath).isDirectory())
.forEach(yearPath => {
fs.readdirSync(yearPath)
.filter(entry => entry.match(/^\d{2}$/))
.map(month => path.join(yearPath, month))
.filter(monthPath => fs.statSync(monthPath).isDirectory())
.forEach(monthPath => {
fs.readdirSync(monthPath)
.filter(entry => path.extname(entry) == '.md')
.forEach(mdFile => {
const mdPath = path.join(monthPath, mdFile)
console.log(mdPath)
const destPath = path.join(memoDir, mdFile)
// Copy
fs.copyFileSync(mdPath, destPath)
// Change time
const stats = fs.statSync(mdPath)
fs.utimesSync(destPath, stats.mtime, stats.mtime)
// const destStats = fs.statSync(destPath)
// console.log(`atime: ${destStats.atime}`)
// console.log(`mtime: ${destStats.mtime}`)
// console.log(`btime: ${destStats.birthtime}`)
})
})
})
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.