1
- # This script uses 7-Zip to compress files and folders in the ${folderName }/XMLsource directory into a zip file.
1
+ # This script uses 7-Zip to compress files and directory in the ${docDirPath }/XMLsource directory into a zip file.
2
2
3
- # Read the name of the folder from the argument passed to the script
4
- $folderName = $args [0 ]
5
- if (-not $folderName ) {
6
- Write-Host " Error: No folder name specified. Usage: Zip-It.ps1 <FolderName >"
3
+
4
+ $docDirPath = $args [0 ]
5
+ if (-not $docDirPath ) {
6
+ Write-Host " Error: No docDirPath specified. Usage: Zip-It.ps1 <docDirPath >"
7
7
exit 1
8
8
}
9
9
10
- $fileName = GetDirName $folderName
10
+ $currentDir = (Get-Location ).Path + " /"
11
+ Write-Host " Current directory: $currentDir "
12
+
13
+ if (IsRelativePath $docDirPath ) {
14
+ $docDirPath = Join-Path - Path $currentDir - basePath $docDirPath
15
+ }
16
+
17
+ $docDirPath = NormalizeDirPath $docDirPath
18
+
19
+ $fileName = GetDirName $docDirPath
11
20
$fileNameNoExt = $fileName.Substring (0 , $fileName.LastIndexOf (' .' ))
12
21
$fileExtension = $fileName.Substring ($fileName.LastIndexOf (' .' ) + 1 )
13
22
14
23
Write-Host " Staring the compression process..."
15
24
16
- $currentDir = Get-Location
17
- Write-Host " Current directory: $currentDir "
18
-
19
- # Define the source folder and the output zip file
20
- $sourceFolder = Join-Path - Path $currentDir - ChildPath " $folderName /XMLsource/"
21
- $outputZipFile = Join-Path - Path $currentDir - ChildPath " $folderName /Skeleton/$fileNameNoExt .zip"
25
+ # Define the source directory and the output zip file
26
+ $xmlDir = $docDirPath + " XMLsource/"
27
+ $outputZipFile = $docDirPath + " Skeleton/$fileNameNoExt .zip"
22
28
23
29
# Path to the 7-Zip executable
24
30
$sevenZipPath = " 7z" # Assumes 7-Zip is in the system PATH. Adjust if necessary.
25
31
26
- # Check if the source folder exists
27
- if (-not (Test-Path $sourceFolder )) {
28
- Write-Host " Source folder not found: $sourceFolder "
32
+ # Check if the source directory exists
33
+ if (-not (Test-Path $xmlDir )) {
34
+ Write-Host " Source dir not found: $xmlDir "
29
35
ls
30
36
exit 1
31
37
}
@@ -39,39 +45,21 @@ if (-not (Test-Path $outputDir)) {
39
45
New-Item - ItemType Directory - Path $outputDir - Force | Out-Null
40
46
}
41
47
42
- if (-not (Test-Path $sourceFolder )) {
43
- Write-Host " Source folder not found: $sourceFolder "
44
- exit 1
45
- }
46
-
47
48
# Ensure the destination directory exists
48
49
$outputDir = Split-Path - Path $outputZipFile
49
50
if (-not (Test-Path $outputDir )) {
50
51
Write-Host " Creating output directory: $outputDir "
51
52
New-Item - ItemType Directory - Path $outputDir - Force | Out-Null
52
53
}
53
54
54
- $absoluteSourceFolder = Resolve-Path - Path $sourceFolder
55
- if (-not (Test-Path $absoluteSourceFolder )) {
56
- Write-Host " Error: Source folder not found: $absoluteSourceFolder "
57
- exit 1
58
- }
59
-
60
- $absoluteDestinationFolder = Resolve-Path - Path $outputDir
61
-
62
55
# Change the working directory to the source folder
63
- Write-Host " Changing directory to $absoluteSourceFolder ..."
64
- cd $absoluteSourceFolder
65
- # if ($LASTEXITCODE -ne 0) {
66
- # Write-Host "Error: Failed to change directory to $absoluteSourceFolder"
67
- # exit $LASTEXITCODE
68
- # }
69
-
56
+ Write-Host " Changing directory to $outputDir ..."
57
+ Set-Location - Path $outputDir
70
58
Write-Host " Current directory after change: $ ( Get-Location ) "
71
59
72
- # Compress the files and folders using 7-Zip
73
- Write-Host " Compressing files in $sourceFolder to $absoluteDestinationFolder ..."
74
- & $sevenZipPath a - tzip " $absoluteDestinationFolder / $ fileNameNoExt .zip" " *" | Out-Null
60
+ # Compress the files and directory using 7-Zip
61
+ Write-Host " Compressing files in $xmlDir to $outputDir ..."
62
+ & $sevenZipPath a - tzip " ${outputDir}${ fileNameNoExt} .zip" " *" | Out-Null
75
63
76
64
# Check if the compression was successful using $LASTEXITCODE
77
65
if ($LASTEXITCODE -ne 0 ) {
@@ -86,4 +74,4 @@ if ($LASTEXITCODE -ne 0) {
86
74
exit $LASTEXITCODE
87
75
}
88
76
89
- Write-Host " Compression completed successfully. Zip file created at: $absoluteDestinationFolder "
77
+ Write-Host " Compression completed successfully. Zip file created at: $outputDir "
0 commit comments