Created
November 30, 2020 11:52
-
-
Save timgaunt/6a06cce465923fe975f2797e1cf5ce05 to your computer and use it in GitHub Desktop.
Move files matching a list of strings from one folder to another
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 = "C:\" | |
$targetFolder = "C:\" | |
$regnos = @( | |
"regno" | |
) | |
Write-Host "Folder: $sourceFolder" | |
$folderFiles = Get-ChildItem -Path $sourceFolder -Filter *.jpg -Recurse -File -Name | |
foreach ($r in $regnos) | |
{ | |
foreach($f in $folderFiles -Match $r) | |
{ | |
Write-Host "File $r was found: $f" -foregroundcolor green | |
Move-Item -Path "$sourceFolder$f" -Destination "$targetFolder$f" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment