Created
July 3, 2024 09:42
-
-
Save yuhangch/aac6521029deaa30727ba8482813f3e0 to your computer and use it in GitHub Desktop.
Obsidian journals archived in YYYY/MM/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
// 90% writen by copilot | |
import fs from 'fs' | |
import path from 'path' | |
const ob_vault_path = "path/to/journals/" | |
const all_journal_files = fs.readdirSync(ob_vault_path).filter(file => file.endsWith('.md')) | |
all_journal_files.forEach(file => { | |
const date = file.split('.')[0] | |
const [year, month, day] = date.split('-') | |
if (!year || !month || !day) { | |
console.log(`Invalid date format for ${file}`) | |
return | |
} | |
const new_dir = path.join(ob_vault_path, year, month) | |
const old_file = path.join(ob_vault_path, file) | |
const new_file = path.join(new_dir, file) | |
if (!fs.existsSync(new_dir)) { | |
fs.mkdirSync(new_dir, {recursive: true}) | |
} | |
fs.renameSync(old_file, new_file) | |
console.log(`Moved ${old_file} to ${new_file}`) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment