# Set the compression algorithm options $options = "XPRESS4K", "XPRESS8K", "XPRESS16K", "LZX" # Prompt the user to choose a compression algorithm Write-Host "Please choose a compression algorithm from the following options:" Write-Host $options Write-Host "" # Loop until the user enters a valid option do { $choice = Read-Host "Enter your choice" if ($options -contains $choice) { $algorithm = $choice break } else { Write-Host "Invalid choice. Please enter one of the options." Write-Host "" } } while ($true) # Prompt the user to enter a directory to compress 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'." Write-Host "" # Loop until the user enters a valid directory do { $dir = Read-Host "Enter the directory" if (Test-Path $dir) { break } else { Write-Host "Invalid directory. Please enter a valid path." Write-Host "" } } while ($true) # Check if the user entered multiple directories $count = ($dir -split '"').Count - 1 # If the user entered multiple directories, ask them to format them correctly if ($count -gt 1) { 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." Write-Host "For example: `"`C:\Users\User\Documents\Assassin's Creed Valhalla\*`" `"`C:\Users\User\Documents\3DMark\*`" `"`C:\Users\User\Documents\4a games\*`"" Write-Host "" exit } # Notify the user of the compression level switch ($algorithm) { "XPRESS4K" { $level = "low" } "XPRESS8K" { $level = "medium" } "XPRESS16K" { $level = "high" } "LZX" { $level = "max" } } Write-Host "You chose $algorithm compression, which is $level level of compression." Write-Host "" # Exclude the windows directory and its subdirectories $exclude = "windows" Get-ChildItem $dir -Directory | ForEach-Object { if ($_.Name -eq $exclude) { $dir = "$dir /EXCLUDE:$_.FullName" } } # Compress the directory and its subdirectories using the chosen algorithm Write-Host "Compressing $dir using $algorithm algorithm..." compact /c /s /a /i /exe:$algorithm $dir Write-Host "" # Display the compression results Write-Host "Compression completed. Here are the results:" compact /q $dir Write-Host "" # End the script pause