Created
December 10, 2019 04:36
-
-
Save mhamri/7b37d244687bc6adc1aee613926c3346 to your computer and use it in GitHub Desktop.
a powershell script to copy only a set of extension with ability to filter
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
$SourceFolderPath = 'C:\repo\PPMS' | |
$FinalFolderPath = 'C:\repo\PPMSF' | |
# Get existing files into arrays: | |
$SourceObjects = Get-ChildItem -Path $SourceFolderPath -Recurse -Include ("*.js", "*.ts", "*.html", "*.cs", "*.cshtml","*.ts", "*.json" , "*.svg", "*.css", "*.scss", "*.csproj", "*.dcproj", "*.gif", "*.sh", "*.yml", "*.bat", "*.ps1", "*.jpg", "*.jpeg", "*.png" ) | |
# $FinalObjects = Get-ChildItem -Path $FinalFolderPath -Recurse | |
# $hash=@{} | |
# Loop all files in the source folder: | |
foreach($file in $SourceObjects) | |
{ | |
# $file | Format-Table | Out-String|% {Write-Host $_} | |
# Using the basename property (which ignores file extension), if the $FinalPics | |
# array contains a basename equal to the basename of $file, then copy it: | |
# if($FinalPics.BaseName -notcontains $file.BaseName) | |
# { | |
$pathToCopy=($file.FullName -replace [regex]::Escape($SourceFolderPath),$FinalFolderPath) | |
if ($pathToCopy -match [regex]::Escape('\node_modules\') ` | |
-or $pathToCopy -match [regex]::Escape('\obj\') ` | |
-or $pathToCopy -match [regex]::Escape('\bin\') ` | |
-or $pathToCopy -match [regex]::Escape('\dist\') ` | |
-or $pathToCopy -match [regex]::Escape('\netcoreapp2.2') ` | |
-or $pathToCopy -match [regex]::Escape('\.vscode') ` | |
) | |
{ | |
continue; | |
} | |
# $hash[$file.extension]++; | |
New-Item -ItemType File -Path $pathToCopy -Force; | |
Copy-Item -Path $file.FullName -Destination $pathToCopy -Recurse; | |
# } | |
} | |
# Write-Host ($hash | Out-String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment