Skip to content

Instantly share code, notes, and snippets.

@DaveGoosem
Created October 24, 2016 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaveGoosem/bcfcd3ea0c1d67085f78e9d3ff0e4ada to your computer and use it in GitHub Desktop.
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
$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