Skip to content

Instantly share code, notes, and snippets.

@timgaunt
Created November 30, 2020 11:52
Show Gist options
  • Save timgaunt/6a06cce465923fe975f2797e1cf5ce05 to your computer and use it in GitHub Desktop.
Save timgaunt/6a06cce465923fe975f2797e1cf5ce05 to your computer and use it in GitHub Desktop.
Move files matching a list of strings from one folder to another
$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