Created
November 19, 2023 08:01
-
-
Save cashwu/be4af28b37c5a7c33b0fe11313ce2b02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 檢查是否安裝了 7z | |
| if ! command -v 7zz &> /dev/null; then | |
| echo "錯誤:未安裝 7z。請先安裝 7z 後再運行此腳本。" | |
| exit 1 | |
| fi | |
| # 定位到包含 ZIP 檔案的資料夾 | |
| #cd /path/to/directory | |
| # 尋找所有的 ZIP 檔案並進行處理 | |
| for file in *.zip; do | |
| # 確保檔案存在 | |
| if [[ -f "$file" ]]; then | |
| # 解壓縮 ZIP 檔案 | |
| unzip "$file" | |
| # 移除副檔名,獲得檔案名稱 | |
| filename=$(basename "$file" .zip) | |
| # 使用 7z 壓縮,壓縮率設為最高 | |
| 7zz a -t7z -mx=9 "$filename.7z" "$filename" | |
| # 測試壓縮檔案的完整性 | |
| if 7zz t "$filename.7z"; then | |
| echo "7z 檔案測試通過:$filename.7z" | |
| # 刪除原始 ZIP 檔案和解壓縮後的檔案/資料夾 | |
| rm -r "$file" "$filename" | |
| else | |
| echo "警告:7z 檔案測試失敗:$filename.7z,保留原始 ZIP 檔案。" | |
| fi | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment