A simple command-line utility that recursively searches a directory tree and copies all matching files to a single flat destination directory.
CopyFlatten.exe <source-directory> <destination-directory> <file-pattern>
Parameters:
source-directory
- The root directory to search recursivelydestination-directory
- The target directory where all files will be copied (created if it doesn't exist)file-pattern
- The file pattern to match (supports wildcards like*.dll
,*.txt
, etc.)
- Recursively searches the source directory for files matching the pattern
- Creates the destination directory if it doesn't exist
- Copies all matching files to the destination directory (flattened structure)
- Overwrites existing files in the destination if they have the same name
CopyFlatten.exe "C:\MyProject\bin" "C:\AllDlls" "*.dll"
Copies all .dll
files from any subdirectory of C:\MyProject\bin
into C:\AllDlls
.
CopyFlatten.exe "C:\Photos" "C:\AllPhotos" "*.jpg"
Flattens a photo directory structure, copying all JPG files to a single folder.
CopyFlatten.exe "C:\Application" "C:\Configs" "*.config"
Extracts all configuration files from an application directory tree.
CopyFlatten.exe "C:\Source" "C:\Destination" "*.*"
Copies every file from the source directory tree into a flat structure.
Gather all shared libraries from a complex project structure:
CopyFlatten.exe "C:\Solution\Projects" "C:\Deploy\Libraries" "*.dll"
Extract all assets of a specific type from a game or application:
CopyFlatten.exe "C:\Game\Assets" "C:\ExtractedTextures" "*.png"
Collect log files from multiple subdirectories:
CopyFlatten.exe "C:\Logs\2023" "C:\AllLogs" "*.log"
Gather documentation files from various project folders:
CopyFlatten.exe "C:\Projects" "C:\AllDocs" "*.md"
Collect build outputs from multiple projects:
CopyFlatten.exe "C:\Solution" "C:\BuildOutputs" "*.exe"
Before (Source Structure):
C:\MyProject\
├── Core\
│ ├── MyApp.Core.dll
│ └── Utils\
│ └── MyApp.Utils.dll
├── Data\
│ └── MyApp.Data.dll
└── Web\
├── MyApp.Web.dll
└── Plugins\
└── MyApp.Plugins.dll
After Running: CopyFlatten.exe "C:\MyProject" "C:\FlatOutput" "*.dll"
C:\FlatOutput\
├── MyApp.Core.dll
├── MyApp.Utils.dll
├── MyApp.Data.dll
├── MyApp.Web.dll
└── MyApp.Plugins.dll
@echo off
echo Flattening DLL files...
CopyFlatten.exe "%SOURCE_DIR%" "%DEPLOY_DIR%\libs" "*.dll"
echo Flattening config files...
CopyFlatten.exe "%SOURCE_DIR%" "%DEPLOY_DIR%\configs" "*.config"
echo Done!
$sourceDir = "C:\Build\Output"
$deployDir = "C:\Deploy"
# Flatten different file types to separate directories
& "CopyFlatten.exe" $sourceDir "$deployDir\Libraries" "*.dll"
& "CopyFlatten.exe" $sourceDir "$deployDir\Executables" "*.exe"
& "CopyFlatten.exe" $sourceDir "$deployDir\Configs" "*.config"
Write-Host "Files flattened successfully!"
# In a build script
echo "Collecting build artifacts..."
./CopyFlatten "/build/output" "/artifacts/binaries" "*.dll"
./CopyFlatten "/build/output" "/artifacts/executables" "*.exe"
Pattern | Matches |
---|---|
*.dll |
All DLL files |
*.exe |
All executable files |
*.txt |
All text files |
*.config |
All configuration files |
*.* |
All files with extensions |
MyApp.* |
All files starting with "MyApp" |
*.log |
All log files |
test*.cs |
C# files starting with "test" |
- Files with the same name will be overwritten in the destination
- The last file processed (alphabetically) will be the final version
- Consider this when flattening directories with duplicate filenames
If multiple files have the same name but are in different source directories:
Source/
├── Folder1/config.xml ← This will be overwritten
└── Folder2/config.xml ← This will be the final file
Only the last config.xml
processed will remain in the destination.