Reputation: 23
I have two folders with information, one has abc12.jpg and the other abc12.json [or .bat, etc you get the idea]. I can't figure out how to modify my code to move files from the .json folder out to better see what files still need their .jpg [and future other same name files]
Could someone poke me in the right direction..
# Specify the folders to compare
$sourceFolder = "C:\SourceFolder"
$targetFolder = "C:\TargetFolder"
$destinationFolder = "C:\DestinationFolder"
# Get the files in the source folder
$sourceFiles = Get-ChildItem -Path $sourceFolder -File -Recurse
# Get the files in the target folder
$targetFiles = Get-ChildItem -Path $targetFolder -File -Recurse
# Compare the files and find the unique files in the source folder
$uniqueFiles = Compare-Object -ReferenceObject $sourceFiles -DifferenceObject $targetFiles -Property Name, Length -PassThru | Where-Object {$_.SideIndicator -eq "<="}
# Move the unique files to the destination folder
foreach ($file in $uniqueFiles) {
$destinationPath = Join-Path $destinationFolder $file.Name
Move-Item -Path $file.FullName -Destination $destinationPath
}
Upvotes: 0
Views: 52