system_configuration/moviedrop.ps1

45 lines
1.4 KiB
PowerShell
Raw Permalink Normal View History

2023-03-31 00:23:48 -07:00
$charA = [int][char]'A'
$charL = [int][char]'L'
$charM = [int][char]'M'
$charZ = [int][char]'Z'
$rangeFirst = $charA..$charL
$rangeSecond = $charM..$charZ
$pathRoot = "/zfs/data/videos/Movies"
$pathFrom = "/zfs/data/videos/MovieDrop"
$movies = Get-ChildItem -Path $pathFrom
foreach ($movie in $movies) {
$name = $movie.Name.Trim()
if ($name -match "^A ") {
$name = $name.Substring(2).Trim()
} elseif ($name -match "^An ") {
$name = $name.Substring(3).Trim()
} elseif ($name -match "^The ") {
$name = $name.Substring(4).Trim()
}
$letter = $name[0]
$nameSecondChar = [int][char]($name.ToUpper()[1])
$letterPair1 = "$letter-$($letter)L"
$letterPair2 = "$($letter)M-$($letter)Z"
$targetFolder = $null
if ($nameSecondChar -in $rangeFirst) {
$targetFolder = $letterPair1
} elseif ($nameSecondChar -in $rangeSecond) {
$targetFolder = $letterPair2
} else {
# handle the case where the title is like "I, Robot" or "O.M.G." or similar
$targetFolder = $letterPair1
}
if ($letter -match '\d') {
# The title starts with a numeric character
$targetFolder = "00-99"
}
$targetPath = Join-Path -Path $pathRoot -ChildPath $targetFolder
2023-03-31 00:50:01 -07:00
Write-Host "Move-Item -Path '$($movie.FullName)' -Destination '$($targetPath)'"
2023-03-31 00:23:48 -07:00
Move-Item -Path $movie.FullName -Destination $targetPath -Force -ErrorAction Continue | Out-Null
2023-03-31 00:46:15 -07:00
}
chown cbrand:users $pathRoot