Ei kuvausta

LZX-Compression-Automated.ps1 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Set the compression algorithm options
  2. $options = "XPRESS4K", "XPRESS8K", "XPRESS16K", "LZX"
  3. # Prompt the user to choose a compression algorithm
  4. Write-Host "Please choose a compression algorithm from the following options:"
  5. Write-Host $options
  6. Write-Host ""
  7. # Loop until the user enters a valid option
  8. do {
  9. $choice = Read-Host "Enter your choice"
  10. if ($options -contains $choice) {
  11. $algorithm = $choice
  12. break
  13. }
  14. else {
  15. Write-Host "Invalid choice. Please enter one of the options."
  16. Write-Host ""
  17. }
  18. }
  19. while ($true)
  20. # Prompt the user to enter a directory to compress
  21. Write-Host "Please enter a directory to compress. You can copy the path by shift-right clicking on the folder and selecting 'Copy as path'."
  22. Write-Host ""
  23. # Loop until the user enters a valid directory
  24. do {
  25. $dir = Read-Host "Enter the directory"
  26. if (Test-Path $dir) {
  27. break
  28. }
  29. else {
  30. Write-Host "Invalid directory. Please enter a valid path."
  31. Write-Host ""
  32. }
  33. }
  34. while ($true)
  35. # Check if the user entered multiple directories
  36. $count = ($dir -split '"').Count - 1
  37. # If the user entered multiple directories, ask them to format them correctly
  38. if ($count -gt 1) {
  39. Write-Host "You entered multiple directories. Please remove all spaces after any `"` and add a `*` after any `\` prior to `"` for the script to continue successfully."
  40. Write-Host "For example: `"`C:\Users\User\Documents\Assassin's Creed Valhalla\*`" `"`C:\Users\User\Documents\3DMark\*`" `"`C:\Users\User\Documents\4a games\*`""
  41. Write-Host ""
  42. exit
  43. }
  44. # Notify the user of the compression level
  45. switch ($algorithm) {
  46. "XPRESS4K" { $level = "low" }
  47. "XPRESS8K" { $level = "medium" }
  48. "XPRESS16K" { $level = "high" }
  49. "LZX" { $level = "max" }
  50. }
  51. Write-Host "You chose $algorithm compression, which is $level level of compression."
  52. Write-Host ""
  53. # Exclude the windows directory and its subdirectories
  54. $exclude = "windows"
  55. Get-ChildItem $dir -Directory | ForEach-Object {
  56. if ($_.Name -eq $exclude) {
  57. $dir = "$dir /EXCLUDE:$_.FullName"
  58. }
  59. }
  60. # Compress the directory and its subdirectories using the chosen algorithm
  61. Write-Host "Compressing $dir using $algorithm algorithm..."
  62. compact /c /s /a /i /exe:$algorithm $dir
  63. Write-Host ""
  64. # Display the compression results
  65. Write-Host "Compression completed. Here are the results:"
  66. compact /q $dir
  67. Write-Host ""
  68. # End the script
  69. pause

Powered by TurnKey Linux.