File tree 2 files changed +67
-0
lines changed
2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ @ echo off
2
+ setlocal enabledelayedexpansion
3
+
4
+ @ REM Check if 2 or 3 arguments are provided
5
+ if " %~2 " == " " (
6
+ echo Usage: %0 ^ < folder_path^ > ^ < zip_file_path^ > [new_folder_name]
7
+ exit /b 1
8
+ )
9
+
10
+ set " folder_path = %~1 "
11
+ set " zip_file_path = %~2 "
12
+ set " new_folder_name = %~3 "
13
+
14
+ @ REM Set default new folder name if not provided
15
+ if " %new_folder_name% " == " " (
16
+ set " new_folder_name = %~n1 -injected"
17
+ )
18
+
19
+ @ REM Step 1: Copy the folder recursively to a new folder
20
+ xcopy /s /e /i " %folder_path% " " %new_folder_name% "
21
+
22
+ @ REM Step 2: Decompress the zip file into the new folder, overwriting existing files
23
+ powershell Expand-Archive -Path " %zip_file_path% " -DestinationPath " %new_folder_name% " -Force
24
+
25
+ @ REM Step 3: Compress the files under the new folder to a new zip file
26
+ @ REM powershell Compress-Archive -Path "%new_folder_name%\*" -DestinationPath "%new_folder_name%.zip" -Force
27
+
28
+ @ REM Step 4: Remove the temporary folder
29
+ @ REM rmdir /s /q "%new_folder_name%"
30
+
31
+ echo Task completed successfully.
32
+
33
+ exit /b 0
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # Function to check if a command is available
3
+ check_command () {
4
+ command -v " $1 " > /dev/null 2>&1 || { echo >&2 " Error: $1 is not installed. Aborting." ; exit 1; }
5
+ }
6
+
7
+ # Check required commands
8
+ check_command " cp"
9
+ check_command " unzip"
10
+ check_command " zip"
11
+
12
+ if [ " $# " -lt 2 ]; then
13
+ echo " Usage: $0 <folder_path> <zip_file_path> [dest_folder]"
14
+ exit 1
15
+ fi
16
+
17
+ folder_path=" $1 "
18
+ zip_file_path=" $2 "
19
+ # Generated from folder_path by default
20
+ dest=" ${3:- ${folder_path##*/ } -injected} "
21
+
22
+ # Step 1: Copy the folder recursively to a new folder
23
+ cp -r " $folder_path " " $dest "
24
+
25
+ # Step 2: Decompress the zip file into the new folder, overwriting existing files
26
+ unzip -o " $zip_file_path " -d " $dest "
27
+
28
+ # Step 3: Compress the files under the new folder to a new zip file
29
+ cd " $dest " && zip -r " ../${dest} .zip" * && cd ..
30
+
31
+ # Step 4: Remove the temporary folder
32
+ rm -r " $dest "
33
+
34
+ echo " Task completed successfully."
You can’t perform that action at this time.
0 commit comments