Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #
  2. # Example .\copy-content.ps1 C:\Users\rcarvalhoxavier\files\ csv C:\Users\rcarvalhoxavier\files\unified\file.csv
  3. #
  4.  
  5. param (
  6. [Parameter(Mandatory=$true)][string] $path,
  7. [Parameter(Mandatory=$true)][string] $extension,
  8. [Parameter(Mandatory=$true)][string] $pathNewFile
  9. )
  10.  
  11. #Verify if path exists
  12. if (Test-Path $path) {
  13. #Gets files according the extension
  14. $Files = Get-ChildItem $path* -Include *.$extension | %{ @{Path=$_.FullName} }
  15. [int]$qtd = ($Files.Values).Count
  16. #log how many found
  17. Write-Host $qtd "files found"
  18. #verify how many founded
  19. if($qtd -gt 0){
  20. #removes the new file would by generated -- if not exists, ignore
  21. Remove-Item $pathNewFile -Force -ErrorAction Ignore
  22. #Copy content
  23. foreach ($file in $Files.Values) {
  24. Get-Content $file | Out-File -FilePath $pathNewFile -Append
  25. }
  26. #success :)
  27. Write-Host "Content copied to" $pathNewFile
  28. }
  29. }
  30. else
  31. {
  32. Write-Host "Cannot find path" $path
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement