Repository navigation
Expand file tree
/
Copy pathCopyAssets.ps1
More file actions
81 lines (69 loc) · 2.93 KB
/
Copy pathCopyAssets.ps1
File metadata and controls
81 lines (69 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# If the script is executed from a different working directory than the
# script file location, switch the current working directory to the
# script's directory so relative paths (e.g. src, include) resolve correctly.
$scriptFile = $MyInvocation.MyCommand.Definition
if ($scriptFile) {
try {
$scriptDir = Split-Path -Parent (Resolve-Path -LiteralPath $scriptFile).Path
$currentDir = (Get-Location).Path
if ($currentDir -ne $scriptDir) {
Set-Location $scriptDir
}
}
catch {
# Resolve-Path failed for some reason (e.g. UNC path); ignore and continue
}
}
# Source folder path
$assetsPath = "assets"
$buildDirName = "vs2026_x64"
# Copy "assets/" folder to specified directories ("build/$buildDirName/Debug" and "build/$buildDirName/Release")
Write-Host "Starting to copy assets folder..." -ForegroundColor Green
# Check if source folder exists
if (-not (Test-Path $assetsPath)) {
Write-Host "Error: assets folder not found in current directory!" -ForegroundColor Red
exit 1
}
# Target directory paths array
$targetPaths = @(
"build\$buildDirName\Debug",
"build\$buildDirName\Release"
)
# Counter for successful copies
$copyCount = 0
# Iterate through all target paths
foreach ($targetPath in $targetPaths) {
# Check if target directory exists
if (Test-Path $targetPath) {
# Build complete target path
$fullTargetPath = Join-Path $targetPath "assets"
Write-Host "Copying to: $targetPath" -ForegroundColor Yellow
try {
# Check if destination assets folder exists
if (Test-Path $fullTargetPath) {
# If destination exists, copy the CONTENTS of source folder
# Using "\*" to copy contents, not the folder itself
Copy-Item -Path "$assetsPath\*" -Destination $fullTargetPath -Recurse -Force -ErrorAction Stop
Write-Host " [OK] Updated existing assets folder in $targetPath" -ForegroundColor Green
}
else {
# If destination doesn't exist, copy the entire folder
Copy-Item -Path $assetsPath -Destination $fullTargetPath -Recurse -Force -ErrorAction Stop
Write-Host " [OK] Created new assets folder in $targetPath" -ForegroundColor Green
}
$copyCount++
}
catch {
Write-Host " [ERROR] Failed to copy to $targetPath : $_" -ForegroundColor Red
}
}
else {
Write-Host " [INFO] Skipping $targetPath (directory does not exist)" -ForegroundColor Gray
}
}
# Output summary
Write-Host "`nOperation completed!" -ForegroundColor Green
Write-Host "Successfully updated/copied to $copyCount directories" -ForegroundColor Cyan
if ($copyCount -eq 0) {
Write-Host "Note: No target directories found. Please verify that build/$buildDirName/Debug or build/$buildDirName/Release directories exist." -ForegroundColor Yellow
}