Last active
January 2, 2025 04:26
-
-
Save suwardhana/92cc63172282015d6d513c24661065ca to your computer and use it in GitHub Desktop.
script for export small codebase as txt file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#how to use .\Export-Codebase.ps1 "C:\Path\To\Your\Codebase" "allcodebase.txt" | |
param ( | |
[string]$RootPath, # Parameter 1: Root directory of the codebase | |
[string]$OutputFile # Parameter 2: Output filename | |
) | |
# Check if the root directory exists | |
if (-Not (Test-Path -Path $RootPath)) { | |
Write-Host "Error: The specified root directory does not exist." | |
exit | |
} | |
# Initialize an empty string to store the output | |
$OutputContent = "" | |
# Get all items recursively | |
Get-ChildItem -Path $RootPath -Recurse | ForEach-Object { | |
# Check if the item is a file | |
if ($_ -is [System.IO.FileInfo]) { | |
# Get the relative path | |
$RelativePath = $_.FullName.Replace($RootPath, "") | |
# Append the file path to the output | |
$OutputContent += "## $RelativePath`n" | |
# Append the file content to the output | |
$OutputContent += (Get-Content $_.FullName -Raw) | |
$OutputContent += "`n" | |
} | |
} | |
# Write the output to the specified file | |
$OutputContent | Out-File -FilePath $OutputFile -Encoding UTF8 | |
Write-Host "Codebase exported successfully to $OutputFile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment