Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Example .\copy-content.ps1 C:\Users\rcarvalhoxavier\files\ csv C:\Users\rcarvalhoxavier\files\unified\file.csv
- #
- param (
- [Parameter(Mandatory=$true)][string] $path,
- [Parameter(Mandatory=$true)][string] $extension,
- [Parameter(Mandatory=$true)][string] $pathNewFile
- )
- #Verify if path exists
- if (Test-Path $path) {
- #Gets files according the extension
- $Files = Get-ChildItem $path* -Include *.$extension | %{ @{Path=$_.FullName} }
- [int]$qtd = ($Files.Values).Count
- #log how many found
- Write-Host $qtd "files found"
- #verify how many founded
- if($qtd -gt 0){
- #removes the new file would by generated -- if not exists, ignore
- Remove-Item $pathNewFile -Force -ErrorAction Ignore
- #Copy content
- foreach ($file in $Files.Values) {
- Get-Content $file | Out-File -FilePath $pathNewFile -Append
- }
- #success :)
- Write-Host "Content copied to" $pathNewFile
- }
- }
- else
- {
- Write-Host "Cannot find path" $path
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement