Automatically creating markdown files for your created JD file structure

Hi all,

I’ve started to use JD a few weeks ago and started by sorting my existing files into the structure. Now I’m lazy and I let chatgpt generate me a bash script (usable for mac/linux) to create .md files in every folder which has an id XX.XX for my index.
I’m going with the method to have the index inside the file structure and NOT separate. If you want to have a separate index don’t use this.

What it does:

  • go through all directories and look for folder name with XX.XX
  • check if a .md file with the same name already exists
  • if not, create it and add a mark down heading with the name

That’s it :wink:

Just posting it here in case anybody wants to use it as well:

#!/bin/bash

# Loop through all directories and subdirectories matching the pattern XX.XX
find . -type d | while read -r dir; do
    # Extract folder name without path
    folder_name="$(basename "$dir")"
    
    # Check if folder name starts with the pattern XX.XX (X is a single digit), but can have additional characters after
    if [[ "$folder_name" =~ ^[0-9]{2}\.[0-9]{2}([^0-9].*)?$ ]]; then
        # Create a file inside the folder with the same name as the folder and .md extension
        file_path="$dir/$folder_name.md"
        
        # Only create the file if it doesn't already exist
        if [[ ! -f "$file_path" ]]; then
            echo "# ${folder_name}" > "$file_path"
            echo "Created file: $file_path"
        else
            echo "File already exists: $file_path, skipping."
        fi
    fi
done

Best,
Christian

2 Likes