Repository navigation
Expand file tree
/
Copy pathCodeExport-windows.bat
More file actions
246 lines (205 loc) · 7.75 KB
/
Copy pathCodeExport-windows.bat
File metadata and controls
246 lines (205 loc) · 7.75 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<# : batch portion
@echo off
setlocal
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$lines = Get-Content -LiteralPath '%~f0';" ^
"$marker = [Array]::IndexOf($lines, '# POWERSHELL_START');" ^
"if ($marker -lt 0) { Write-Host 'Fehler: PowerShell-Teil nicht gefunden.'; exit 1 }" ^
"$script = ($lines[($marker + 1)..($lines.Length - 1)] -join [Environment]::NewLine);" ^
"Invoke-Expression $script"
set EXIT_CODE=%ERRORLEVEL%
echo.
if %EXIT_CODE% equ 0 (
echo Export erfolgreich abgeschlossen.
) else (
echo Export mit Fehler beendet (Code: %EXIT_CODE%).
)
pause
exit /b %EXIT_CODE%
: end batch / begin powershell #>
# POWERSHELL_START
$ErrorActionPreference = 'Stop'
$sourceDir = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Path)
$exportDir = Join-Path $sourceDir 'code_export'
$flatDir = Join-Path $exportDir 'alle'
$compressedDir = Join-Path $exportDir 'alle komprimiert'
$includeNames = @(
'.gitignore',
'.gitattributes',
'mvnw',
'mvnw.cmd',
'Dockerfile',
'docker-compose.yml',
'docker-compose.yaml'
)
$includeExtensions = @(
'.java','.kt','.groovy','.xml','.properties','.yml','.yaml','.proto','.html','.css','.js','.ts','.tsx','.jsx',
'.sh','.bat','.cmd','.ps1','.md','.json','.sql','.graphql','.env','.gradle','.txt','.py'
)
$excludeDirs = @(
'target','build','dist','.mvn','.gradle','.git','.idea','.vscode','node_modules','__pycache__','.venv','venv','logs','code_export'
)
function Should-IncludeFile {
param([string]$filePath)
$name = [System.IO.Path]::GetFileName($filePath)
if ($includeNames -contains $name) { return $true }
$ext = [System.IO.Path]::GetExtension($filePath).ToLowerInvariant()
return $includeExtensions -contains $ext
}
function Is-ExcludedPath {
param([string]$relativePath)
$segments = $relativePath -split '[\\/]'
foreach ($segment in $segments) {
if ($excludeDirs -contains $segment) {
return $true
}
}
return $false
}
Write-Host ''
Write-Host '🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀'
Write-Host 'UNIVERSELLES CODE EXPORT TOOL (Windows)'
Write-Host '🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀 🚀'
Write-Host ''
Write-Host "Quelle: $sourceDir"
Write-Host "Output: $exportDir"
Write-Host ''
Write-Host ('=' * 80)
Write-Host 'SCHRITT 1: VORBEREITUNG'
Write-Host ('=' * 80)
if (Test-Path -LiteralPath $exportDir) {
Write-Host "Lösche alten Export-Ordner: $exportDir"
Remove-Item -LiteralPath $exportDir -Recurse -Force
}
New-Item -ItemType Directory -Path $exportDir -Force | Out-Null
Write-Host "✓ Export-Ordner bereit: $exportDir"
Write-Host ''
Write-Host ('=' * 80)
Write-Host 'SCHRITT 2: STRUKTURIERTER EXPORT'
Write-Host ('=' * 80)
$structuredCount = 0
$allFiles = Get-ChildItem -LiteralPath $sourceDir -Recurse -File -Force
foreach ($file in $allFiles) {
$fullPath = $file.FullName
if ($fullPath.StartsWith($exportDir, [System.StringComparison]::OrdinalIgnoreCase)) {
continue
}
$relative = [System.IO.Path]::GetRelativePath($sourceDir, $fullPath)
if (Is-ExcludedPath $relative) {
continue
}
if (-not (Should-IncludeFile $fullPath)) {
continue
}
$outPath = Join-Path $exportDir ($relative + '.txt')
$outDir = [System.IO.Path]::GetDirectoryName($outPath)
if (-not [string]::IsNullOrWhiteSpace($outDir)) {
New-Item -ItemType Directory -Path $outDir -Force | Out-Null
}
$content = Get-Content -LiteralPath $fullPath -Raw -Encoding UTF8
$header = "Path: $fullPath`r`n==================================================`r`n`r`n"
Set-Content -LiteralPath $outPath -Value ($header + $content) -Encoding UTF8
$structuredCount++
}
Write-Host "✓ $structuredCount Dateien im strukturierten Format exportiert"
Write-Host ''
Write-Host ('=' * 80)
Write-Host 'SCHRITT 3: FLACHER EXPORT (alle)'
Write-Host ('=' * 80)
New-Item -ItemType Directory -Path $flatDir -Force | Out-Null
$flatCount = 0
$txtFiles = Get-ChildItem -LiteralPath $exportDir -Recurse -File -Filter '*.txt' -Force
foreach ($txt in $txtFiles) {
$txtFull = $txt.FullName
if ($txtFull.StartsWith($flatDir, [System.StringComparison]::OrdinalIgnoreCase)) { continue }
if ($txtFull.StartsWith($compressedDir, [System.StringComparison]::OrdinalIgnoreCase)) { continue }
$base = $txt.Name
$target = Join-Path $flatDir $base
if (Test-Path -LiteralPath $target) {
$stem = [System.IO.Path]::GetFileNameWithoutExtension($base)
$ext = [System.IO.Path]::GetExtension($base)
$i = 1
do {
$candidate = Join-Path $flatDir ($stem + '_' + $i + $ext)
$i++
} while (Test-Path -LiteralPath $candidate)
$target = $candidate
}
Copy-Item -LiteralPath $txtFull -Destination $target -Force
$flatCount++
}
Write-Host "✓ $flatCount Dateien im flachen Format exportiert"
Write-Host ''
Write-Host ('=' * 80)
Write-Host 'SCHRITT 4: KOMPRIMIERTER EXPORT (alle komprimiert)'
Write-Host ('=' * 80)
New-Item -ItemType Directory -Path $compressedDir -Force | Out-Null
$compressedCount = 0
$topDirs = Get-ChildItem -LiteralPath $exportDir -Directory -Force |
Where-Object { $_.Name -ne 'alle' -and $_.Name -ne 'alle komprimiert' }
foreach ($dir in $topDirs) {
$groupFiles = Get-ChildItem -LiteralPath $dir.FullName -Recurse -File -Filter '*.txt' -Force | Sort-Object FullName
if ($groupFiles.Count -eq 0) { continue }
$outFile = Join-Path $compressedDir ($dir.Name + '.txt')
$builder = New-Object System.Text.StringBuilder
[void]$builder.AppendLine("SERVICE: $($dir.Name)")
[void]$builder.AppendLine(('=' * 80))
[void]$builder.AppendLine("Total files: $($groupFiles.Count)")
[void]$builder.AppendLine(('=' * 80))
[void]$builder.AppendLine('')
foreach ($f in $groupFiles) {
$c = Get-Content -LiteralPath $f.FullName -Raw -Encoding UTF8
[void]$builder.AppendLine($c)
[void]$builder.AppendLine('')
[void]$builder.AppendLine(('─' * 80))
[void]$builder.AppendLine('')
}
Set-Content -LiteralPath $outFile -Value $builder.ToString() -Encoding UTF8
Write-Host " ✓ $($dir.Name).txt ($($groupFiles.Count) Dateien)"
$compressedCount++
}
$rootTxt = Get-ChildItem -LiteralPath $exportDir -File -Filter '*.txt' -Force | Sort-Object FullName
if ($rootTxt.Count -gt 0) {
$rootOut = Join-Path $compressedDir 'root.txt'
$builder = New-Object System.Text.StringBuilder
[void]$builder.AppendLine('ROOT LEVEL FILES')
[void]$builder.AppendLine(('=' * 80))
[void]$builder.AppendLine("Total files: $($rootTxt.Count)")
[void]$builder.AppendLine(('=' * 80))
[void]$builder.AppendLine('')
foreach ($f in $rootTxt) {
$c = Get-Content -LiteralPath $f.FullName -Raw -Encoding UTF8
[void]$builder.AppendLine($c)
[void]$builder.AppendLine('')
[void]$builder.AppendLine(('─' * 80))
[void]$builder.AppendLine('')
}
Set-Content -LiteralPath $rootOut -Value $builder.ToString() -Encoding UTF8
Write-Host " ✓ root.txt ($($rootTxt.Count) Dateien)"
$compressedCount++
}
$totalBytes = (Get-ChildItem -LiteralPath $exportDir -Recurse -File -Force | Measure-Object -Property Length -Sum).Sum
if (-not $totalBytes) { $totalBytes = 0 }
$totalMb = [Math]::Round($totalBytes / 1MB, 2)
Write-Host ''
Write-Host ('=' * 80)
Write-Host 'ZUSAMMENFASSUNG'
Write-Host ('=' * 80)
Write-Host ''
Write-Host '📁 Strukturierter Export:'
Write-Host " └─ $structuredCount Dateien mit Pfad-Header"
Write-Host ''
Write-Host '📄 Flacher Export (alle):'
Write-Host " └─ $flatCount Dateien ohne Ordner-Struktur"
Write-Host ''
Write-Host '🗜️ Komprimierter Export (alle komprimiert):'
Write-Host " └─ $compressedCount Sammel-Dateien"
Write-Host ''
Write-Host "💾 Speichergröße: $totalMb MB"
Write-Host ''
Write-Host "📍 Speicherort: $exportDir"
Write-Host ''
Write-Host ('=' * 80)
Write-Host '✓ EXPORT ABGESCHLOSSEN!'
Write-Host ('=' * 80)
Write-Host ''