Created
October 24, 2016 11:41
-
-
Save DaveGoosem/bcfcd3ea0c1d67085f78e9d3ff0e4ada to your computer and use it in GitHub Desktop.
Quick Powershell script to copy files and keep folder structure with file type filtering
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
$SourceFolder = "D:\Downloads" | |
$DestinationFolder = "D:\test" | |
$IncludeFiles = ("*.jpeg","*.jpg") | |
Get-ChildItem $SourceFolder -Recurse -Include $IncludeFiles | Where-Object {$_.LastWriteTime -gt $ChangesStarted} | ForEach-Object { | |
$PathArray = $_.FullName.Replace($SourceFolder,"").ToString().Split('\') | |
$Folder = $DestinationFolder | |
for ($i=1; $i -lt $PathArray.length-1; $i++) { | |
$Folder += "\" + $PathArray[$i] | |
if (!(Test-Path $Folder)) { | |
New-Item -ItemType directory -Path $Folder | |
} | |
} | |
$NewPath = Join-Path $DestinationFolder $_.FullName.Replace($SourceFolder,"") | |
Copy-Item $_.FullName -Destination $NewPath | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment