Geen omschrijving

LZX-Compression-Automated.bat 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Prompt the user to enter a drive letter for compression
  2. $drive = Read-Host "Please enter a drive letter for compression (e.g. C, D, E, F, etc.)"
  3. # Validate the drive letter input
  4. if ($drive -match "^[A-Z]$") {
  5. # Append a colon to the drive letter
  6. $drive = $drive + ":"
  7. } else {
  8. # Display an error message and exit the script
  9. Write-Error "Invalid drive letter. Please enter a single uppercase letter from A to Z."
  10. Exit
  11. }
  12. # Define the file types to exclude from compression
  13. $exclude = @("*.zip", "*.mp4", "*.mp3", "*.flv", "*.jpg", "*.png", "*.gif", "*.pdf", "*.rar", "*.7z", "*.tar", "*.gz", "*.wav", "*.aac", "*.ogg", "*.mkv", "*.avi", "*.docx", "*.xlsx", "*.pptx", "*.ttf", "*.otf", "*.woff")
  14. # Get all the files and folders on the drive
  15. $items = Get-ChildItem -Path $drive -Recurse
  16. # Loop through each item and check if it is compressible
  17. foreach ($item in $items) {
  18. # Skip the item if it is a directory or a symbolic link
  19. if ($item.PSIsContainer -or $item.LinkType) {
  20. continue
  21. }
  22. # Skip the item if it matches any of the excluded file types
  23. $skip = $false
  24. foreach ($ext in $exclude) {
  25. if ($item.Name -like $ext) {
  26. $skip = $true
  27. break
  28. }
  29. }
  30. if ($skip) {
  31. continue
  32. }
  33. # Compress the item using compact.exe with the /C, /I, /EXE:lzx and /EXCLUDE:exclude.txt options
  34. compact /C /I /EXE:lzx /EXCLUDE:exclude.txt $item.FullName
  35. }

Powered by TurnKey Linux.