powershell to recursively spool out code in markdown format

A one-liner to recursively gather code from sub-folders and then output it in a Markdown-style

$Text = foreach ($file in $(dir .\themes\hyde -recurse -exclude "*.png" | ? attributes -ne 'Directory' | select fullname)) 
{
    [string]$filename = $file.fullname
    write-output "`#`#`# $filename"
    write-output "````````"
    get-content $filename
    write-output "````````" 
}

$Text > x.txt

Produces output a like this:

D:\hugo\sites\example.com\themes\hyde\archetypes\default.md

+++
Description = ""
Tags = ["Development", "golang"]
Categories = ["Development", "GoLang"]
menu = "main"
+++

D:\hugo\sites\example.com\themes\hyde\layouts_default\list.html

{{ partial "head.html" . }}
<body class="{{ .Site.Params.themeColor }}">

{{ partial "sidebar.html" . }}

<div class="content container">
<ul class="posts">
{{ range .Data.Pages }}

Advertisements