Skip to content

Commit cf662b7

Browse files
committed
Adjust dir manip
1 parent fcaeeb9 commit cf662b7

File tree

1 file changed

+27
-39
lines changed

1 file changed

+27
-39
lines changed

scripts/Zip-It.ps1

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
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+
13+
if (IsRelativePath $docDirPath) {
14+
$docDirPath = Join-Path -Path $currentDir -basePath $docDirPath
15+
}
16+
17+
$docDirPath = NormalizeDirPath $docDirPath
18+
19+
$fileName = GetDirName $docDirPath
1120
$fileNameNoExt = $fileName.Substring(0, $fileName.LastIndexOf('.'))
1221
$fileExtension = $fileName.Substring($fileName.LastIndexOf('.') + 1)
1322

1423
Write-Host "Staring the compression process..."
1524

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"
2228

2329
# Path to the 7-Zip executable
2430
$sevenZipPath = "7z" # Assumes 7-Zip is in the system PATH. Adjust if necessary.
2531

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"
2935
ls
3036
exit 1
3137
}
@@ -39,39 +45,21 @@ if (-not (Test-Path $outputDir)) {
3945
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
4046
}
4147

42-
if (-not (Test-Path $sourceFolder)) {
43-
Write-Host "Source folder not found: $sourceFolder"
44-
exit 1
45-
}
46-
4748
# Ensure the destination directory exists
4849
$outputDir = Split-Path -Path $outputZipFile
4950
if (-not (Test-Path $outputDir)) {
5051
Write-Host "Creating output directory: $outputDir"
5152
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
5253
}
5354

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-
6255
# 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
7058
Write-Host "Current directory after change: $(Get-Location)"
7159

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
7563

7664
# Check if the compression was successful using $LASTEXITCODE
7765
if ($LASTEXITCODE -ne 0) {
@@ -86,4 +74,4 @@ if ($LASTEXITCODE -ne 0) {
8674
exit $LASTEXITCODE
8775
}
8876

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

Comments
 (0)