Last active
April 6, 2017 10:16
-
-
Save pizycki/7b76597fcaab8ae12feca62368093a0b to your computer and use it in GitHub Desktop.
Concating files into single file
This file contains 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
param( | |
[String] $Location, | |
[String] $Pattern=".*", | |
[String] $Seperator="" | |
) | |
# Create file | |
$tempFile = "temp.txt" | |
New-Item -Name $tempFile -ItemType "file" -Force | |
# Collect files | |
$files = Get-ChildItem -Recurse -Path $Location ` | |
| where { !($_.PsIsContainer) } ` | |
| where { $_.Name -notmatch $tempFile } ` | |
| where { $_.Name -match $Pattern } ` | |
| sort -Property FullName | |
# Enlist files | |
$files | %{ Write-Host $_.FullName } | |
# Concat | |
# $files | gc | Add-Content $tempFile | |
foreach($f in $files){ | |
$fileContent = Get-Content $f.FullName | |
$fileContent = $fileContent + $Seperator | |
Add-Content $tempFile $fileContent | |
} | |
# Notepad gen.sql | |
& .\$tempFile | |
# Sleep for while | |
sleep 1 | |
# Delete temp file | |
rm $tempFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment