Jump to content

Is it possible to delete 500,000 files in a folder at once without manually deleting?

Randel1980
Go to solution Solved by Oshino Shinobu,

Wrote a quick powershell script to do this. 

 

It will remove anything in Folder A that does not match in Folder B. It will not remove anything from folder B. Obviously, replace the paths with the ones you require. 

 

$FolderA = Get-childitem "D:\test\Folder1"
$FolderB = Get-childitem  "D:\test\Folder2"


$FilestoRemove = Compare-Object $FolderA $FolderB -Property BaseName -PassThru | Where-Object {$_.SideIndicator -eq '<='}
foreach ($file in $FilestoRemove) {
    Remove-Item -Path $file.FullName
}

I'd advise testing this first on some test folders to make sure it does what you want it to. Make a backup before using it if you can. 

 

Disclaimer here: I won't be held responsible if you use the script incorrectly or it otherwise removes files not as you intended. 

So I have two folders located in drive D

 

Folder "A" contains 750,000 files.

Folder "B" contains 250,000 files.

 

If I want to delete all  500,000 files in "A" folder whose name do not match in folder "B". How do I do that?

Link to comment
Share on other sites

Link to post
Share on other sites

should just be able to right click the desired folder and click delete. Might take a hot minute though. 

 

Edit: Looks like I misunderstood what op wanted (again. Thank you to my poor English). 

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Randel1980 said:

So I have two folders located in drive D

 

Folder "A" contains 750,000 files.

Folder "B" contains 250,000 files.

 

If I want to delete all files in "A" folder whose name do not match in folder "B". How do I do that?

Copy one of the contents of a folder into the other folder, and when it asks tell it to skip duplicate files. Then delete the old folder :)

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, The Torrent said:

Copy one of the contents of a folder into the other folder, and when it asks tell it to skip duplicate files. Then delete the old folder :)

This.

And if you want to keep them separated, after they've overwritten the files in Folder A, they will still be selected, so you can move them back to Folder B without any issues.

CPU: AMD Ryzen 3700x / GPU: Asus Radeon RX 6750XT OC 12GB / RAM: Corsair Vengeance LPX 2x8GB DDR4-3200
MOBO: MSI B450m Gaming Plus / NVME: Corsair MP510 240GB / Case: TT Core v21 / PSU: Seasonic 750W / OS: Win 10 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, The Torrent said:

Copy one of the contents of a folder into the other folder, and when it asks tell it to skip duplicate files. Then delete the old folder :)

Those files are irreplaceable, files from folder "A" are 1080P images. Files from folder "B" are 4K images. They just have identical names.

Link to comment
Share on other sites

Link to post
Share on other sites

I think this is what you're looking for: https://stackoverflow.com/questions/43967926/compare-folder-contents-with-another-folder-and-delete

Since you want to delete the 'differences' between these two.

 

Be sure to first make a backup of the folders, in case anything goes wrong

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Wrote a quick powershell script to do this. 

 

It will remove anything in Folder A that does not match in Folder B. It will not remove anything from folder B. Obviously, replace the paths with the ones you require. 

 

$FolderA = Get-childitem "D:\test\Folder1"
$FolderB = Get-childitem  "D:\test\Folder2"


$FilestoRemove = Compare-Object $FolderA $FolderB -Property BaseName -PassThru | Where-Object {$_.SideIndicator -eq '<='}
foreach ($file in $FilestoRemove) {
    Remove-Item -Path $file.FullName
}

I'd advise testing this first on some test folders to make sure it does what you want it to. Make a backup before using it if you can. 

 

Disclaimer here: I won't be held responsible if you use the script incorrectly or it otherwise removes files not as you intended. 

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, Oshino Shinobu said:

Wrote a quick powershell script to do this. 

 

It will remove anything in Folder A that does not match in Folder B. It will not remove anything from folder B. Obviously, replace the paths with the ones you require. 

 


$FolderA = Get-childitem "D:\test\Folder1"
$FolderB = Get-childitem  "D:\test\Folder2"


$FilestoRemove = Compare-Object $FolderA $FolderB -Property BaseName -PassThru | Where-Object {$_.SideIndicator -eq '<='}
foreach ($file in $FilestoRemove) {
    Remove-Item -Path $file.FullName
}

I'd advise testing this first on some test folders to make sure it does what you want it to. Make a backup before using it if you can. 

 

Disclaimer here: I won't be held responsible if you use the script incorrectly or it otherwise removes files not as you intended. 

You are amazing!!! This script works like a charm, it saves me a lot of time. Thank you.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Randel1980 said:

Those files are irreplaceable, files from folder "A" are 1080P images. Files from folder "B" are 4K images. They just have identical names.

As long as they have same name it should still do it.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Randel1980 said:

Those files are irreplaceable, files from folder "A" are 1080P images. Files from folder "B" are 4K images. They just have identical names.

Would've worked if they had the same name and same extension. 

Their size doesn't matter.

CPU: AMD Ryzen 3700x / GPU: Asus Radeon RX 6750XT OC 12GB / RAM: Corsair Vengeance LPX 2x8GB DDR4-3200
MOBO: MSI B450m Gaming Plus / NVME: Corsair MP510 240GB / Case: TT Core v21 / PSU: Seasonic 750W / OS: Win 10 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

-> Moved to Programs, Apps and Websites

^^^^ That's my post ^^^^
<-- This is me --- That's your scrollbar -->
vvvv Who's there? vvvv

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×