Skip to content

Instantly share code, notes, and snippets.

@obar1
Created October 24, 2025 09:21
Show Gist options
  • Save obar1/9bb3ea06a4e5f9181e872915f697fec4 to your computer and use it in GitHub Desktop.
Save obar1/9bb3ea06a4e5f9181e872915f697fec4 to your computer and use it in GitHub Desktop.
list dirs and save in md
# Define output file
$outputFile = "Subfolders.md"
# Get current directory
$currentDir = Get-Location
# Get all subfolders
$subfolders = Get-ChildItem -Path $currentDir -Directory
# Start Markdown content
$markdownContent = "# Subfolders in `$($currentDir)`n`n"
# Add each subfolder as a bullet point with space replaced by %20
foreach ($folder in $subfolders) {
$encodedName = $folder.Name -replace ' ', '%20'
$markdownContent += "* [here](./$encodedName/readme.md)`n"
}
# Save to file
$markdownContent | Out-File -FilePath $outputFile -Encoding UTF8
Write-Host "Markdown file saved as $outputFile"
@obar1
Copy link
Author

obar1 commented Oct 24, 2025

bash version

#!/bin/bash

# Define output file
output_file="Subfolders.md"

# Get current directory
current_dir=$(pwd)

# Start Markdown content
echo "# Subfolders in \`$current_dir\`" > "$output_file"
echo "" >> "$output_file"

# Loop through subfolders
for folder in */ ; do
    # Remove trailing slash and encode spaces
    folder_name="${folder%/}"
    encoded_name="${folder_name// /%20}"
    
    # Append to markdown file
    echo "* here" >> "$output_file"
done

echo "Markdown file saved as $output_file"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment