Skip to content

Instantly share code, notes, and snippets.

@pizycki
Last active April 6, 2017 10:16
Show Gist options
  • Save pizycki/7b76597fcaab8ae12feca62368093a0b to your computer and use it in GitHub Desktop.
Save pizycki/7b76597fcaab8ae12feca62368093a0b to your computer and use it in GitHub Desktop.
Concating files into single file
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