Skip to content

Commit a315b02

Browse files
committed
Fiddling with paths
1 parent 4c66ca0 commit a315b02

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

Main.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,22 @@ Write-TimedMessage "Minimizing Administrator window" -StartNewStep
8686
Minimize-Window "Administrator: C:\actions"
8787
Write-TimedMessage "Window minimized"
8888

89-
89+
$originalSrcDir = $srcDir
9090

9191
foreach ($folder in $folders) {
92+
Write-Host "========================="
93+
# Reset the source directory to the original value
94+
$srcDir = $originalSrcDir
95+
9296
Write-TimedMessage "Processing folder: $folder" -StartNewStep
9397
$fileExtension = $folder.Substring($folder.LastIndexOf('.') + 1)
98+
Write-Host "File extension: $fileExtension"
9499
$app = Get-OfficeApp -FileExtension $fileExtension
95100

96101
$ext = ""
97102
if ($app -ne "Access") {
98103
$ext = "zip"
99-
Write-TimedMessage "Creating Zip file and renaming to Office document target" -StartNewStep
104+
Write-TimedMessage "Creating Zip file and renaming to Office document target with path ${srcDir}${folder}" -StartNewStep
100105
. "$PSScriptRoot/scripts/Zip-It.ps1" "${srcDir}${folder}"
101106
Write-TimedMessage "Zip file created"
102107
}
@@ -116,6 +121,8 @@ foreach ($folder in $folders) {
116121
$buildVbaScriptPath = "$PSScriptRoot/scripts/Build-VBA.ps1"
117122
$success = Invoke-ScriptWithTimeout -ScriptPath $buildVbaScriptPath -Arguments @("${srcDir}${folder}", "$app") -TimeoutSeconds 30
118123

124+
Write-Host "srcDir: ${srcDir}"
125+
119126
if (-not $success) {
120127
Write-TimedMessage "🔴 Build-VBA.ps1 execution timed out or failed for ${folder}. Continuing with next file..."
121128

@@ -129,5 +136,4 @@ foreach ($folder in $folders) {
129136
}
130137

131138
Write-TimedMessage "🟢 Completed processing folder: $folder"
132-
Write-Host "========================="
133139
}

scripts/Rename-It.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ $fileExtension = $fileName.Substring($fileName.LastIndexOf('.') + 1)
2929

3030
# Create a copy of the zip/document file in the $folderName/Skeleton folder at the top level
3131
$copySource = "$folderName/Skeleton/$fileNameNoExt.$ext"
32-
$renameDestinationFolder = "$rootSrcDir/out"
33-
$renameDestinationFilePath = "$renameDestinationFolder/$fileNameNoExt.$fileExtension"
32+
$renameDestinationFolder = $rootSrcDir + "out/"
33+
$renameDestinationFilePath = "$renameDestinationFolder$fileNameNoExt.$fileExtension"
3434

3535
# Create rename destination folder if it doesn't exist
3636
if (-not (Test-Path $renameDestinationFolder)) {

scripts/Zip-It.ps1

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# This script uses 7-Zip to compress files and directory in the ${docDirPath}/XMLsource directory into a zip file.
22

33

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>"
77
exit 1
88
}
9+
Write-Host "dirPath: $dirPath"
10+
11+
# Import utility functions
12+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
13+
. "$scriptPath/utils/Path.ps1"
914

1015
$currentDir = (Get-Location).Path + "/"
1116
Write-Host "Current directory: $currentDir"
12-
$docDirPath = GetAbsPath -path $docDirPath -basePath $currentDir
17+
$docDirPath = GetAbsPath -path $dirPath -basePath $currentDir
1318
Write-Host "Using docDirPath: $docDirPath"
1419

1520
$docDirPath = NormalizeDirPath $docDirPath
@@ -22,7 +27,8 @@ Write-Host "Staring the compression process..."
2227

2328
# Define the source directory and the output zip file
2429
$xmlDir = $docDirPath + "XMLsource/"
25-
$outputZipFile = $docDirPath + "Skeleton/$fileNameNoExt.zip"
30+
$outputDir = $docDirPath + "Skeleton/"
31+
$outputZipFile = $outputDir + "$fileNameNoExt.zip"
2632

2733
# Path to the 7-Zip executable
2834
$sevenZipPath = "7z" # Assumes 7-Zip is in the system PATH. Adjust if necessary.
@@ -35,29 +41,21 @@ if (-not (Test-Path $xmlDir)) {
3541
}
3642

3743
# Ensure the destination directory exists
38-
$outputDir = Split-Path -Path $outputZipFile
3944
Write-Host "Output directory: $outputDir"
4045

4146
if (-not (Test-Path $outputDir)) {
4247
Write-Host "Creating output directory: $outputDir"
4348
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
4449
}
4550

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-
5351
# 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
5654
Write-Host "Current directory after change: $(Get-Location)"
5755

5856
# Compress the files and directory using 7-Zip
5957
Write-Host "Compressing files in $xmlDir to $outputDir..."
60-
& $sevenZipPath a -tzip "${outputDir}${fileNameNoExt}.zip" "*" | Out-Null
58+
& $sevenZipPath a -tzip "$outputZipFile" "*" | Out-Null
6159

6260
# Check if the compression was successful using $LASTEXITCODE
6361
if ($LASTEXITCODE -ne 0) {
@@ -72,4 +70,9 @@ if ($LASTEXITCODE -ne 0) {
7270
exit $LASTEXITCODE
7371
}
7472

73+
if (-not (Test-Path $outputZipFile)) {
74+
Write-Host "Error: Zip file not found after compression: $outputZipFile"
75+
exit 1
76+
}
77+
7578
Write-Host "Compression completed successfully. Zip file created at: $outputDir"

0 commit comments

Comments
 (0)