Last active
March 22, 2020 23:10
-
-
Save robderickson/88781b8fd0d173037c6c9b27ebd3cefb to your computer and use it in GitHub Desktop.
Example of how to sort files into folders based on file name.
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
# Assume file names are like ThatShow - S01E03 | |
# Assume they will go in their respective subfoders in a directory called Media (M:\Media) | |
$ParentPath = 'M:\Media' | |
# Get collection of .mp4 files from working directory | |
$files = Get-ChildItem *.mp4 | |
foreach ($file in $files) { | |
# Parse the title from the file name | |
$ShowTitle = $file.Name.Split('-')[0].TrimEnd() | |
# Parse the season from the file name | |
$Season = "Season " + [decimal]$file.Name.Split('-')[1].TrimStart().Substring(1,2) | |
# Put it all together | |
$Path = "$ParentPath\$ShowTitle\$Season" | |
# Move it | |
Move-Item $file $Path | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment