moviedrop.ps1 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. $charA = [int][char]'A'
  2. $charL = [int][char]'L'
  3. $charM = [int][char]'M'
  4. $charZ = [int][char]'Z'
  5. $rangeFirst = $charA..$charL
  6. $rangeSecond = $charM..$charZ
  7. $pathRoot = "/zfs/data/videos/Movies"
  8. $pathFrom = "/zfs/data/videos/MovieDrop"
  9. $movies = Get-ChildItem -Path $pathFrom
  10. foreach ($movie in $movies) {
  11. $name = $movie.Name.Trim()
  12. if ($name -match "^A ") {
  13. $name = $name.Substring(2).Trim()
  14. } elseif ($name -match "^An ") {
  15. $name = $name.Substring(3).Trim()
  16. } elseif ($name -match "^The ") {
  17. $name = $name.Substring(4).Trim()
  18. }
  19. $letter = $name[0]
  20. $nameSecondChar = [int][char]($name.ToUpper()[1])
  21. $letterPair1 = "$letter-$($letter)L"
  22. $letterPair2 = "$($letter)M-$($letter)Z"
  23. $targetFolder = $null
  24. if ($nameSecondChar -in $rangeFirst) {
  25. $targetFolder = $letterPair1
  26. } elseif ($nameSecondChar -in $rangeSecond) {
  27. $targetFolder = $letterPair2
  28. } else {
  29. # handle the case where the title is like "I, Robot" or "O.M.G." or similar
  30. $targetFolder = $letterPair1
  31. }
  32. if ($letter -match '\d') {
  33. # The title starts with a numeric character
  34. $targetFolder = "00-99"
  35. }
  36. $targetPath = Join-Path -Path $pathRoot -ChildPath $targetFolder
  37. Write-Host "Move-Item -Path '$($movie.FullName)' -Destination '$($targetPath)'"
  38. Move-Item -Path $movie.FullName -Destination $targetPath -Force -ErrorAction Continue | Out-Null
  39. }
  40. chown cbrand:users $pathRoot