Eliminate files in folder that are duplicated in another folder tree

0

I have two folders. One of them (Folder 1) has pictures and the other (Folder 2) has multiple sub-folders with pictures. I wanted to find the pictures in Folder 1 that are duplicated in Folder 2 or any of its sub-folders and delete them. Moving the non-duplicates to a new folder (Folder 3) is also an option.

Can I do this using the command line? Do I need a script?

I tried using FreeFileSynch but it doesn't work if Folder 2 has sub folders.

Edit: The robocopy suggestion is interesting but while it can copy sub-folders and their content, I don't think it can copy only the files inside the sub-folders.

user1766833

Posted 2017-03-16T01:06:53.477

Reputation: 15

Thanks for the answer but I don't think Robocopy can compare files in a folder to files in multiple subfolders. – user1766833 – 2017-03-16T02:15:24.713

Answers

0

Here's the right way to do it, without the external downloads. It looks like a lot at first, but once you've done it, it's very easy. It works in all Windows versions from 7 back to 95. For our example assume that you're comparing two directories named 'A' and 'B'. 1. run cmd.exe to get a command prompt. (In Windows 7, the powershell won't work for this, FYI.) Then do it again, so that you have two of them open next to each other. 2. in each window go to the directories that you want to compare. (Using 'cd' commands. If you're not comfortable with this, then you should probably go with the external utilities, unless you want to learn command prompt stuff.) 3. type 'dir /b > A.txt' into one window and 'dir /b > B.txt' into the other. You'll now have two text files that list the contents of each directory. The /b flag means bare, which strips the directory listing down to file names only. 4. move B.txt into the same folder as A.txt. 5. type 'fc A.txt B.txt'. The command 'fc' means file compare. This will spit out a list of the differences between the two files, with an extra line of text above and below each difference, so you know where they are. For more options on how the output is formatted, type 'fc /?' at the prompt. You can also pipe the differences into another file by using something like 'fc A.txt B.txt > differences.txt'. Have fun.

Aiden Hong

Posted 2017-03-16T01:06:53.477

Reputation: 16

All was going well until I noticed 'dir /b > B.txt' only gives me the sub-folders inside B folder, not the files inside its sub-folders, which is what I needed. – user1766833 – 2017-03-16T02:44:46.223

0

So the solution I found is not perfect but works.

I copied all the files from Folder 1 to a temporary folder flattening the hierarchy with the forfiles command in the command line. Then I moved the files from the temporary folder to Folder 2 replacing some of those. The files that were moved were deleted because they were already in Folder 1.

1) In command line: forfiles /p C:\folder1 /s /c "cmd /c copy @path C:\temporaryfolder"

2) In Windows Explorer: Move files from the Temporary Folder to Folder 2 and replace the existing files. While the files are selected, delete them. The remaining files are the files from Folder 2 that were not in Folder 1.

user1766833

Posted 2017-03-16T01:06:53.477

Reputation: 15