Skip to content

Commit 4c66ca0

Browse files
committed
Adjust dir manip
1 parent fcaeeb9 commit 4c66ca0

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

scripts/Zip-It.ps1

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
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.
22

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>"
77
exit 1
88
}
99

10-
$fileName = GetDirName $folderName
10+
$currentDir = (Get-Location).Path + "/"
11+
Write-Host "Current directory: $currentDir"
12+
$docDirPath = GetAbsPath -path $docDirPath -basePath $currentDir
13+
Write-Host "Using docDirPath: $docDirPath"
14+
15+
$docDirPath = NormalizeDirPath $docDirPath
16+
17+
$fileName = GetDirName $docDirPath
1118
$fileNameNoExt = $fileName.Substring(0, $fileName.LastIndexOf('.'))
1219
$fileExtension = $fileName.Substring($fileName.LastIndexOf('.') + 1)
1320

1421
Write-Host "Staring the compression process..."
1522

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"
23+
# Define the source directory and the output zip file
24+
$xmlDir = $docDirPath + "XMLsource/"
25+
$outputZipFile = $docDirPath + "Skeleton/$fileNameNoExt.zip"
2226

2327
# Path to the 7-Zip executable
2428
$sevenZipPath = "7z" # Assumes 7-Zip is in the system PATH. Adjust if necessary.
2529

26-
# Check if the source folder exists
27-
if (-not (Test-Path $sourceFolder)) {
28-
Write-Host "Source folder not found: $sourceFolder"
30+
# Check if the source directory exists
31+
if (-not (Test-Path $xmlDir)) {
32+
Write-Host "Source dir not found: $xmlDir"
2933
ls
3034
exit 1
3135
}
@@ -39,39 +43,21 @@ if (-not (Test-Path $outputDir)) {
3943
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
4044
}
4145

42-
if (-not (Test-Path $sourceFolder)) {
43-
Write-Host "Source folder not found: $sourceFolder"
44-
exit 1
45-
}
46-
4746
# Ensure the destination directory exists
4847
$outputDir = Split-Path -Path $outputZipFile
4948
if (-not (Test-Path $outputDir)) {
5049
Write-Host "Creating output directory: $outputDir"
5150
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
5251
}
5352

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-
6253
# 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-
54+
Write-Host "Changing directory to $outputDir..."
55+
Set-Location -Path $outputDir
7056
Write-Host "Current directory after change: $(Get-Location)"
7157

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
58+
# Compress the files and directory using 7-Zip
59+
Write-Host "Compressing files in $xmlDir to $outputDir..."
60+
& $sevenZipPath a -tzip "${outputDir}${fileNameNoExt}.zip" "*" | Out-Null
7561

7662
# Check if the compression was successful using $LASTEXITCODE
7763
if ($LASTEXITCODE -ne 0) {
@@ -86,4 +72,4 @@ if ($LASTEXITCODE -ne 0) {
8672
exit $LASTEXITCODE
8773
}
8874

89-
Write-Host "Compression completed successfully. Zip file created at: $absoluteDestinationFolder"
75+
Write-Host "Compression completed successfully. Zip file created at: $outputDir"

0 commit comments

Comments
 (0)