-
-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathExportSourceFiles.ps1
More file actions
59 lines (49 loc) · 2.09 KB
/
ExportSourceFiles.ps1
File metadata and controls
59 lines (49 loc) · 2.09 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
# Get the directory where the script is located
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Function to search for "Basis Foundation" in parent directories
function Find-BasisFoundationDir {
param (
[string]$currentDir
)
while ($currentDir -and (Split-Path -Leaf $currentDir) -ne "Basis Foundation") {
$currentDir = Split-Path -Parent $currentDir
}
return $currentDir
}
# Find the "Basis Foundation" directory
$basisFoundationDir = Find-BasisFoundationDir -currentDir $scriptDir
# Validate that we found the expected directory
if (-not $basisFoundationDir) {
Write-Host "Error: Could not find 'Basis Foundation' directory in parent structure."
exit 1
}
# Define source and destination relative to "Basis Foundation"
$source = Join-Path $basisFoundationDir "Basis Unity\Basis Server"
$destination = Join-Path $basisFoundationDir "Basis Unity\Basis\Packages\com.basis.server"
# Ensure source exists before proceeding
if (-Not (Test-Path -Path $source)) {
Write-Host "Error: Source directory not found - $source"
exit 1
}
# Remove all .cs files in the destination directory
Get-ChildItem -Path $destination -Recurse -Include *.cs | Remove-Item -Force
# Copy files from source to destination, excluding .dll, .asmdef, and obj folders
Get-ChildItem -Path $source -Recurse | Where-Object {
$_.Extension -notin @('.dll', '.asmdef') -and
$_.FullName -notmatch '\\obj\\' -and
$_.FullName -notlike '*\Contrib\PersistentKv*'
} | ForEach-Object {
# Compute relative path and determine destination path
$relativePath = $_.FullName.Substring($source.Length)
$destinationPath = Join-Path $destination $relativePath
# Ensure the destination folder exists
$destinationFolder = Split-Path -Parent $destinationPath
if (-not (Test-Path -Path $destinationFolder)) {
New-Item -ItemType Directory -Path $destinationFolder -Force
}
# Copy the file to the destination
if (-not $_.PSIsContainer) {
Copy-Item -Path $_.FullName -Destination $destinationPath -Force
}
}
Write-Host "Files copied successfully!"