1
1
# This script uses 7-Zip to compress files and directory in the ${docDirPath}/XMLsource directory into a zip file.
2
2
3
3
4
- $docDirPath = $args [0 ]
5
- if (-not $docDirPath ) {
6
- Write-Host " Error: No docDirPath specified. Usage: Zip-It.ps1 <docDirPath >"
4
+ $dirPath = $args [0 ]
5
+ if (-not $dirPath ) {
6
+ Write-Host " Error: No dirPath specified. Usage: Zip-It.ps1 <dirPath >"
7
7
exit 1
8
8
}
9
+ Write-Host " dirPath: $dirPath "
10
+
11
+ # Import utility functions
12
+ $scriptPath = Split-Path - Parent $MyInvocation.MyCommand.Path
13
+ . " $scriptPath /utils/Path.ps1"
9
14
10
15
$currentDir = (Get-Location ).Path + " /"
11
16
Write-Host " Current directory: $currentDir "
12
- $docDirPath = GetAbsPath - path $docDirPath - basePath $currentDir
17
+ $docDirPath = GetAbsPath - path $dirPath - basePath $currentDir
13
18
Write-Host " Using docDirPath: $docDirPath "
14
19
15
20
$docDirPath = NormalizeDirPath $docDirPath
@@ -22,7 +27,8 @@ Write-Host "Staring the compression process..."
22
27
23
28
# Define the source directory and the output zip file
24
29
$xmlDir = $docDirPath + " XMLsource/"
25
- $outputZipFile = $docDirPath + " Skeleton/$fileNameNoExt .zip"
30
+ $outputDir = $docDirPath + " Skeleton/"
31
+ $outputZipFile = $outputDir + " $fileNameNoExt .zip"
26
32
27
33
# Path to the 7-Zip executable
28
34
$sevenZipPath = " 7z" # Assumes 7-Zip is in the system PATH. Adjust if necessary.
@@ -35,29 +41,21 @@ if (-not (Test-Path $xmlDir)) {
35
41
}
36
42
37
43
# Ensure the destination directory exists
38
- $outputDir = Split-Path - Path $outputZipFile
39
44
Write-Host " Output directory: $outputDir "
40
45
41
46
if (-not (Test-Path $outputDir )) {
42
47
Write-Host " Creating output directory: $outputDir "
43
48
New-Item - ItemType Directory - Path $outputDir - Force | Out-Null
44
49
}
45
50
46
- # Ensure the destination directory exists
47
- $outputDir = Split-Path - Path $outputZipFile
48
- if (-not (Test-Path $outputDir )) {
49
- Write-Host " Creating output directory: $outputDir "
50
- New-Item - ItemType Directory - Path $outputDir - Force | Out-Null
51
- }
52
-
53
51
# Change the working directory to the source folder
54
- Write-Host " Changing directory to $outputDir ... "
55
- Set-Location - Path $outputDir
52
+ Write-Host " Changing directory to $xmlDir "
53
+ Set-Location - Path $xmlDir
56
54
Write-Host " Current directory after change: $ ( Get-Location ) "
57
55
58
56
# Compress the files and directory using 7-Zip
59
57
Write-Host " Compressing files in $xmlDir to $outputDir ..."
60
- & $sevenZipPath a - tzip " ${outputDir}${fileNameNoExt} .zip " " *" | Out-Null
58
+ & $sevenZipPath a - tzip " $outputZipFile " " *" | Out-Null
61
59
62
60
# Check if the compression was successful using $LASTEXITCODE
63
61
if ($LASTEXITCODE -ne 0 ) {
@@ -72,4 +70,9 @@ if ($LASTEXITCODE -ne 0) {
72
70
exit $LASTEXITCODE
73
71
}
74
72
73
+ if (-not (Test-Path $outputZipFile )) {
74
+ Write-Host " Error: Zip file not found after compression: $outputZipFile "
75
+ exit 1
76
+ }
77
+
75
78
Write-Host " Compression completed successfully. Zip file created at: $outputDir "
0 commit comments