Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This Windows PowerShell script takes an inventory of one folder and for each file that exists will execute a delete in another folder. I wrote this to deal with some bizarre node/gulp race conditions while doing image optimization. So if a file has been processed (compressed) it is ok to delete it from the images_in folder.
# 20160601 Scott C. Krause
# Remove files that exist within out from the in folder
# This Windows PowerShell script takes an inventory of one folder and for each file that exists will execute a delete in another folder.
# I wrote this to deal with some bizarre node/gulp race conditions while doing image optimization.
# So if a file has been processed (compressed) it is ok to delete it from the images_in folder.
$dest = "\\compressed"
$source = "\\images_product\images_in"
$in = Get-ChildItem $source
$out = Get-ChildItem $dest
Compare-Object -ReferenceObject $in -IncludeEqual $out -Property Name | Where-Object {$_.SideIndicator -eq "=="} | ForEach-Object {
Remove-Item "$($source)\$($_.name)" -Recurse
Write-Host "Removing $($source)\$($_.name)"
}
@neodigm

This comment has been minimized.

Copy link
Owner Author

@neodigm neodigm commented Aug 22, 2016

20160601 Scott C. Krause
Remove files that exist within out from the in folder
This Windows PowerShell script takes an inventory of one folder and for each file that exists will execute a delete in another folder.
I wrote this to deal with some bizarre node/gulp race conditions while doing image optimization.
So if a file has been processed (compressed) it is ok to delete it from the images_in folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.