Skip to content

Instantly share code, notes, and snippets.

@robderickson
Last active March 22, 2020 23:10
Show Gist options
  • Save robderickson/88781b8fd0d173037c6c9b27ebd3cefb to your computer and use it in GitHub Desktop.
Save robderickson/88781b8fd0d173037c6c9b27ebd3cefb to your computer and use it in GitHub Desktop.
Example of how to sort files into folders based on file name.
# 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