Created
April 26, 2024 09:28
-
-
Save winkler-winsen/7f34bbf76a4717290cee5303bd623da7 to your computer and use it in GitHub Desktop.
PowerShell copy files with filter and maintain directory structure
This file contains hidden or 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
$sourceDir = 'C:\SourceDir\' | |
$targetDir = 'C:\DestDir\' | |
Get-ChildItem $sourceDir -Filter "*" -Recurse |` | |
Where-Object {$_.LastWriteTime -gt (Get-Date).addDays(-1) -and -not $_.PSIsContainer} |` | |
foreach { | |
$targetFile = $targetDir + $_.FullName.SubString($sourceDir.Length); | |
New-Item -ItemType File -Path $targetFile -Force; | |
Copy-Item $_.FullName -destination $targetFile | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment