Last active
July 31, 2019 20:47
-
-
Save ElliotFriend/f796745808039ea2ccc19a79ed3ce9b7 to your computer and use it in GitHub Desktop.
I subscribe to Grow Curriculum (https://growcurriculum.org). I downloaded all the files they had available, but didn't want to manually extract, move, rename, etc. So, this file came into existence.
This file contains 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
$growDestination = "C:\Users\evoris\Grow Curriculum\2019-2020\" | |
$growDirectory = "C:\Users\evoris\Grow Curriculum\" | |
$hashPatterns = @{ | |
"PLAN" = "01 Planning" | |
"CURR" = "02 Curriculum" | |
"DISC" = "03 Discipleship" | |
"EVEN" = "04 Events" | |
"VOLU" = "05 Volunteers" | |
"PARE" = "06 Parents" | |
"GAME" = "07 Games" | |
} | |
Get-ChildItem -Path $growDirectory -Filter *.zip | ForEach-Object { | |
$archive = $_.FullName | |
$7zipExe = "C:\Program Files\7-Zip\7z.exe" | |
# Check if key exists | |
$itemKey = $_.Name.Substring(0,4) | |
if ($hashPatterns.ContainsKey($itemKey)) { | |
$itemValue = $hashPatterns[$itemKey] | |
& $7zipExe d $archive "__MACOSX" | |
$newDir = Join-Path $growDestination $itemValue | |
$newDir = Join-Path $newDir $_.BaseName.Substring(4).Replace("_", " ") | |
& $7zipExe x $archive -o"$newDir" | |
Get-ChildItem -Path $newDir -Filter *.pdf | Rename-Item -NewName { $_.Name -replace '^(_)(.+pdf)$', '$2' } | |
} else { echo "No key found for $_.Name" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment