Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created October 24, 2019 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/03f0a49279d0e64b557940c642f01825 to your computer and use it in GitHub Desktop.
Save dance2die/03f0a49279d0e64b557940c642f01825 to your computer and use it in GitHub Desktop.
ls | % {
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_split?view=powershell-6
$parsed = $_.Name -split '(\d{4})-(\d{2})-(\d{2})-(.*)'
$year = $parsed[1];
$month = $parsed[2];
$day = $parsed[3];
$name = $parsed[4];
$newDir = "$year/$month/$day";
# Create a new directory matching the folder name.
# https://social.technet.microsoft.com/Forums/office/en-US/98232ee2-846c-4f49-9284-95d28dc5b2cb/recursively-create-directories?forum=winserverpowershell
new-item $newDir -ItemType Directory
# New File name without date prefix and with .mdx extension
$newFile = [IO.Path]::ChangeExtension("$newDir/$name", ".mdx")
Write-output $newFile
Copy-Item $_.Name $newFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment