Skip to content

Instantly share code, notes, and snippets.

@iniznet
Created July 13, 2024 22:58
Show Gist options
  • Save iniznet/3eb3932901342cabb07957164e3c8261 to your computer and use it in GitHub Desktop.
Save iniznet/3eb3932901342cabb07957164e3c8261 to your computer and use it in GitHub Desktop.
Concatenate your entire project code especially web development into a single file in Windows
$Source = "C:\absolute-path"
$OutputFile = "all.txt"
$Prefix = "path: "
$MaxRetries = 5
$RetryWaitSeconds = 2
function Write-WithRetry {
param(
[string]$Path,
[string]$Value
)
$retryCount = 0
$success = $false
while (-not $success -and $retryCount -lt $MaxRetries) {
try {
Add-Content -Path $Path -Value $Value -ErrorAction Stop
$success = $true
}
catch {
$retryCount++
Write-Warning "Attempt $retryCount failed. Retrying in $RetryWaitSeconds seconds..."
Start-Sleep -Seconds $RetryWaitSeconds
}
}
if (-not $success) {
Write-Error "Failed to write to file after $MaxRetries attempts."
}
}
Get-ChildItem -Path $Source -Recurse -File | ForEach-Object {
$filePath = $_.FullName
$relativePath = $Prefix + $filePath.Substring($Source.Length).TrimStart('\')
Write-WithRetry -Path $OutputFile -Value $relativePath
Get-Content $filePath | ForEach-Object {
Write-WithRetry -Path $OutputFile -Value $_
}
Write-WithRetry -Path $OutputFile -Value "`n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment