|
|
@@ -1,81 +1,20 @@
|
|
1
|
|
-# Set the compression algorithm options
|
|
2
|
|
-$options = "XPRESS4K", "XPRESS8K", "XPRESS16K", "LZX"
|
|
3
|
|
-
|
|
4
|
|
-# Prompt the user to choose a compression algorithm
|
|
5
|
|
-Write-Host "Please choose a compression algorithm from the following options:"
|
|
6
|
|
-Write-Host $options
|
|
7
|
|
-Write-Host ""
|
|
8
|
|
-
|
|
9
|
|
-# Loop until the user enters a valid option
|
|
10
|
|
-do {
|
|
11
|
|
- $choice = Read-Host "Enter your choice"
|
|
12
|
|
- if ($options -contains $choice) {
|
|
13
|
|
- $algorithm = $choice
|
|
14
|
|
- break
|
|
15
|
|
- }
|
|
16
|
|
- else {
|
|
17
|
|
- Write-Host "Invalid choice. Please enter one of the options."
|
|
18
|
|
- Write-Host ""
|
|
19
|
|
- }
|
|
20
|
|
-}
|
|
21
|
|
-while ($true)
|
|
22
|
|
-
|
|
23
|
|
-# Prompt the user to enter a directory to compress
|
|
24
|
|
-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'."
|
|
25
|
|
-Write-Host ""
|
|
26
|
|
-
|
|
27
|
|
-# Loop until the user enters a valid directory
|
|
28
|
|
-do {
|
|
29
|
|
- $dir = Read-Host "Enter the directory"
|
|
30
|
|
- if (Test-Path $dir) {
|
|
31
|
|
- break
|
|
32
|
|
- }
|
|
33
|
|
- else {
|
|
34
|
|
- Write-Host "Invalid directory. Please enter a valid path."
|
|
35
|
|
- Write-Host ""
|
|
36
|
|
- }
|
|
37
|
|
-}
|
|
38
|
|
-while ($true)
|
|
39
|
|
-
|
|
40
|
|
-# Check if the user entered multiple directories
|
|
41
|
|
-$count = ($dir -split '"').Count - 1
|
|
42
|
|
-
|
|
43
|
|
-# If the user entered multiple directories, ask them to format them correctly
|
|
44
|
|
-if ($count -gt 1) {
|
|
45
|
|
- 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."
|
|
46
|
|
- Write-Host "For example: `"`C:\Users\User\Documents\Assassin's Creed Valhalla\*`" `"`C:\Users\User\Documents\3DMark\*`" `"`C:\Users\User\Documents\4a games\*`""
|
|
47
|
|
- Write-Host ""
|
|
48
|
|
- exit
|
|
|
1
|
+# Get the list of folders to compress from the clipboard
|
|
|
2
|
+$folders = Get-Clipboard
|
|
|
3
|
+
|
|
|
4
|
+# Set the compression level (Valid values are low, medium, high, max, or blank for default)
|
|
|
5
|
+$level = "high"
|
|
|
6
|
+
|
|
|
7
|
+# Set the recursive option (Valid values are /S or blank for no recursion)
|
|
|
8
|
+$recursive = "/S"
|
|
|
9
|
+
|
|
|
10
|
+# Loop through the folders and invoke compact.exe for each one
|
|
|
11
|
+foreach ($folder in $folders) {
|
|
|
12
|
+ # compact.exe uses advanced compression algorithms to compress the files and folders
|
|
|
13
|
+ # The compression level determines which algorithm is used and how much space is saved
|
|
|
14
|
+ # The pros and cons of each compression level are as follows:
|
|
|
15
|
+ # low: Quick compression, uses XPRESS4K, saves some space, fast and low CPU usage
|
|
|
16
|
+ # medium: Default compression, uses XPRESS8K, saves more space, moderate speed and CPU usage
|
|
|
17
|
+ # high: Low compression, uses XPRESS16K, saves even more space, slow and high CPU usage
|
|
|
18
|
+ # max: Maximum compression, uses LZX, saves the most space, very slow and very high CPU usage
|
|
|
19
|
+ compact /C /S /A /I /EXE:$level $recursive $folder
|
|
49
|
20
|
}
|
|
50
|
|
-
|
|
51
|
|
-# Notify the user of the compression level
|
|
52
|
|
-switch ($algorithm) {
|
|
53
|
|
- "XPRESS4K" { $level = "low" }
|
|
54
|
|
- "XPRESS8K" { $level = "medium" }
|
|
55
|
|
- "XPRESS16K" { $level = "high" }
|
|
56
|
|
- "LZX" { $level = "max" }
|
|
57
|
|
-}
|
|
58
|
|
-
|
|
59
|
|
-Write-Host "You chose $algorithm compression, which is $level level of compression."
|
|
60
|
|
-Write-Host ""
|
|
61
|
|
-
|
|
62
|
|
-# Exclude the windows directory and its subdirectories
|
|
63
|
|
-$exclude = "windows"
|
|
64
|
|
-Get-ChildItem $dir -Directory | ForEach-Object {
|
|
65
|
|
- if ($_.Name -eq $exclude) {
|
|
66
|
|
- $dir = "$dir /EXCLUDE:$_.FullName"
|
|
67
|
|
- }
|
|
68
|
|
-}
|
|
69
|
|
-
|
|
70
|
|
-# Compress the directory and its subdirectories using the chosen algorithm
|
|
71
|
|
-Write-Host "Compressing $dir using $algorithm algorithm..."
|
|
72
|
|
-compact /c /s /a /i /exe:$algorithm $dir
|
|
73
|
|
-Write-Host ""
|
|
74
|
|
-
|
|
75
|
|
-# Display the compression results
|
|
76
|
|
-Write-Host "Compression completed. Here are the results:"
|
|
77
|
|
-compact /q $dir
|
|
78
|
|
-Write-Host ""
|
|
79
|
|
-
|
|
80
|
|
-# End the script
|
|
81
|
|
-pause
|