You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**PowerShell File Combiner** is a PowerShell script that aggregates text-based project files into a single text file, ideal for feeding into large-context-window LLMs like Gemini 2.5 Pro or GPT-4. It generates a directory tree and concatenates file contents while excluding binary files and specified directories, making it perfect for developers preparing codebases for AI analysis.
4
+
5
+
## Features
6
+
7
+
-**Directory Tree Generation**: Creates a visual representation of your project’s folder structure.
8
+
-**File Content Aggregation**: Combines text-based files into a single output file (`CombinedFile.txt` by default).
9
+
-**Binary File Exclusion**: Skips binary files (e.g., `.exe`, `.png`, `.pdf`) based on extensions or null-byte detection.
10
+
-**Customizable Exclusions**: Exclude specific directories (e.g., `node_modules`, `bin`) and files.
11
+
-**Depth Control**: Limit subdirectory recursion with a configurable `MaxDepth` setting.
12
+
-**Error Handling**: Gracefully handles file access issues and logs errors to the output file.
13
+
-**UTF-8 Encoding**: Ensures compatibility with diverse character sets.
14
+
15
+
## Use Cases
16
+
17
+
- Prepare a codebase for AI-driven code analysis or documentation generation.
18
+
- Create a single text file for LLM input to summarize or refactor projects.
19
+
- Generate a project overview with directory structure and file contents.
$OutputPath="CombinedFile.txt"# The name of the output file
3
+
$CurrentDirectory=Get-Location# The current directory where the script is executed
4
+
$SkipBinaryFiles=$true# Set to $true to skip binary files
5
+
$BinaryFileExtensions=@(".exe",".dll",".png",".jpg",".jpeg",".gif",".bmp",".zip",".rar",".7z",".pdf",".mp3",".mp4",".avi",".psd",".class",".jar",".ico") # Extensions to consider as binary
6
+
$ExcludeDirectories=@("node_modules","obj","bin","Migrations") # Directories to exclude
7
+
$ExcludeFiles=@("package-log.json","Combine-Files.ps1",$OutputPath) # Files to exclude (including the script itself and the output)
8
+
$MaxDepth=-1# Set -1 to go through entire structure, or set to a number for example - 3, to search only 3 subfolder levels
9
+
10
+
11
+
#endregion Configuration
12
+
13
+
#region Helper Functions
14
+
15
+
# Function to build the directory tree structure
16
+
functionBuild-DirectoryTree {
17
+
param (
18
+
[string]$Path,
19
+
[int]$Depth=0,
20
+
[string]$Indent=""
21
+
)
22
+
23
+
# Check max depth
24
+
if ($MaxDepth-gt0-and$Depth-gt$MaxDepth) {
25
+
return
26
+
}
27
+
28
+
# Check if directory is in exclude list
29
+
if ($ExcludeDirectories-contains ([System.IO.Path]::GetFileName($Path))) {
Write-Host"Excluding file by name: $($File.FullName)"
118
+
continue# Skip to the next file
119
+
}
120
+
121
+
# Check if the file is located in an excluded directory
122
+
$IsInExcludedDir=$false
123
+
# Ensure the file's directory is a subdirectory of the current execution path and not the root itself.
124
+
# This check is case-insensitive for paths, standard on Windows.
125
+
if ($File.DirectoryName.StartsWith($CurrentDirectory.Path, [System.StringComparison]::OrdinalIgnoreCase) -and$File.DirectoryName.Length-gt$CurrentDirectory.Path.Length) {
126
+
# Get the part of the file's directory path that is relative to the current execution path.
127
+
# e.g., if $CurrentDirectory.Path is 'C:\\Project' and $File.DirectoryName is 'C:\\Project\\src\\bin',
0 commit comments