Ian Jones Logo

Script Kit

Refactor Org Roam Daily files

I used this script to convert a bunch of my org roam daily files into a more hierarchical scructure. So from 2021-04-27.org to journal.2021.04.27.org. This is replicating how Dendron formats its file names to create a structure.

Heres the script:

let dailiesPath = await env('DENDRON_PATH')

const dailiesFiles = await ls(dailiesPath)

const getNewPathForFile = async (fileName) => {
  const oldFilePath = `${dailiesPath}${fileName}`
  const newFilePath = `${dailiesPath}journal.${fileName.split('-').join('.')}`
  try {
    await mv(oldFilePath, newFilePath)
    return newFilePath
  } catch (e) {
    return e

const result = await Promise.all(dailiesFiles.map(getNewPathForFile))


It gets all the files inside of dailiesPath using ls. Then we map over all of these file names and mv the old file name to the new file name.

This could easily be done in Bash as we are just using a JavaScript abstraction but what I like about this is that I already know how to map over a list of entries in JS. I dont need to learn how to do it in bash.