소스 검색

Update 'LZX-Compression-Automated.bat'

nathan 1 년 전
부모
커밋
e8124e1054
1개의 변경된 파일41개의 추가작업 그리고 5개의 파일을 삭제
  1. 41
    5
      LZX-Compression-Automated.bat

+ 41
- 5
LZX-Compression-Automated.bat 파일 보기

@@ -1,5 +1,41 @@
1
-@echo off
2
-compact /c /s /i /a /exe:lzx "C:\Windows.old\*", "C:\Program Files\*", "C:\Program FIles (x86)\*", "C:\Users\*", "D:\*"
3
-echo All files and directories within "D:\", "Windows.old", "Program Files", "Program Files (x86)" and "Users" are compressed via LZX format,
4
-echo presuming that all of these directories exist and files exist within these directories.
5
-pause
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
+
4
+# Validate the drive letter input
5
+if ($drive -match "^[A-Z]$") {
6
+    # Append a colon to the drive letter
7
+    $drive = $drive + ":"
8
+} else {
9
+    # Display an error message and exit the script
10
+    Write-Error "Invalid drive letter. Please enter a single uppercase letter from A to Z."
11
+    Exit
12
+}
13
+
14
+# Define the file types to exclude from compression
15
+$exclude = @("*.zip", "*.mp4", "*.mp3", "*.flv", "*.jpg", "*.png", "*.gif", "*.pdf", "*.rar", "*.7z", "*.tar", "*.gz", "*.wav", "*.aac", "*.ogg", "*.mkv", "*.avi", "*.docx", "*.xlsx", "*.pptx", "*.ttf", "*.otf", "*.woff")
16
+
17
+# Get all the files and folders on the drive
18
+$items = Get-ChildItem -Path $drive -Recurse
19
+
20
+# Loop through each item and check if it is compressible
21
+foreach ($item in $items) {
22
+    # Skip the item if it is a directory or a symbolic link
23
+    if ($item.PSIsContainer -or $item.LinkType) {
24
+        continue
25
+    }
26
+
27
+    # Skip the item if it matches any of the excluded file types
28
+    $skip = $false
29
+    foreach ($ext in $exclude) {
30
+        if ($item.Name -like $ext) {
31
+            $skip = $true
32
+            break
33
+        }
34
+    }
35
+    if ($skip) {
36
+        continue
37
+    }
38
+
39
+    # Compress the item using compact.exe with the /C, /I, /EXE:lzx and /EXCLUDE:exclude.txt options
40
+    compact /C /I /EXE:lzx /EXCLUDE:exclude.txt $item.FullName
41
+}

Powered by TurnKey Linux.