Delete files in foder and sub folders ending in COPY ?

I have a computer that contains lots of photos in subfolders, many files are duplicated with the word 'copy' appended to the filename.

Is there a way to delete these copies which is less tedious than manually selecting them?
LVL 70
Brian PiercePhotographerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

web_trackerComputer Service TechnicianCommented:
I have had good luck with the duplicate cleaner, as mentioned by activematx. It is a good application and it is free. It takes little space on the hard drive and uses little system resources.
0
Brian PiercePhotographerAuthor Commented:
I was rather looking for a script which deleted files with the word COPY in the filename .
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

BillDLCommented:
As long as there aren't any other unrelated files with "copy" comprising the last 4 characters of the file name before the dotted extension, you can use the "DOS" delete command with a wildcard for the file name and extension.

@echo off
c:
cd %userprofile%\pictures
del "*copy.*" /s
pause

The above should change back to the C: Drive just in case the Current Directory is set to another drive letter, and should then change to your home folder's Pictures folder, ie.
C:\Users\<Your-User-Name>\Pictures
and delete all file extensions, where the last 4 characters of the file name are "copy", from the root of your "Pictures" folder and from all sub-folders.

It isn't the safest command to use, firstly because the files aren't sent to the recycle bin, and secondly because there are no checks in there to ensure that the command doesn't delete files it shouldn't, apart from the odd "are you sure" prompt when it encounters read-only or hidden files.  In particular, there is absolutely no checking to see if the file suffixed by "copy" has a matching file with the same extension but without "copy" at the end of the name.

Also of note is the fact that a file named "photocopy.jpg" (or with any other extension) will also be deleted because the file name ends with "copy".  If there is a consistency of naming where there is always an underscore before the word copy, for example "Filename1_copy.jpg", then the command should include that to filter out names like "photocopy",
del *_copy.*"

It can be made a little safer by running separate passes and deleting files with specific extensions on each pass:

@echo off
c:
cd %userprofile%\pictures
del "*copy.jpg" /s
del "*copy.png" /s
del "*copy.bmp" /s
del "*copy.gif" /s
pause

Personally I would prefer that you didn't try to delete files like this, because I wouldn't want to feel responsibe if it deletes files you wanted to keep.

If you want to do a proper comparison for duplicate files, ie to check that the one named "Filename1Copy.jpg" is a duplicate of "Filename1.jpg", that is a lot more involved in a scripted method (although not impossible) where you would actually better using a duplicate file finding Windows utility.

I believe that the following is what I would do, given the same situation, but I'm using Windows XP set to "classic search", which I think allows more control than the file search more recent versions of Windows.

Find all files named   *copy.jpg   in your Documents or Pictures folder and all sub-folders.
Select them all, Right-Click > Copy them (not "cut") > Open Windows Explorer to a new folder created for the purpose > Paste them there.
Return to the Search window and delete the files.

This way the files are all backed up before deletion, just in case you later need one of them.  You could also then run a duplicate file finder utility to verify that all the files copied to your backup folder do have matching image files in the other folders.

The problem with the above method is that if there is more than one file with exactly the same name, you will not be able to paste both the files into the same folder.  You could give it a go first and see whether this is an issue before going back to delete the files in the search window, and if there are only a few instances of "do you want to overwrite ...?", then you could write the paths down and deal with them manually.

An alternative to the the Windows search is the standalone "SearchMyFiles" utility by Nir Sofer, which I use a lot.  It allows a lot more control over what you want to include and exclude, and can be used to find duplicates (http://www.nirsoft.net/articles/find_duplicate_files.html) although it is not specifically intended to be a fully blown duplicate file finder that checks the CRC, MD5, or SHA1 hashes of files.

Do you still want a scripted method?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brian PiercePhotographerAuthor Commented:
Thanks for the warnings - its just that the duplicate file finder method can be tedious - the files in question are all images and will not have the word 'copy' in them normally - they are usually just the names assigned to images by the camera eg IMG08252.CR2.

Its just that in many cases there are copies produced due to windows seemingly wanting to create copies of files for no apparent reason when the user tries to select multiple files with the CTRL key held down.
0
BillDLCommented:
Thank you KCTS

I know the scenario only too well, and I'm sure it has happened to us all at one time.  You have a folder open in Windows Explorer and are in the process of selecting multiple files with the Ctrl + Click method, but as you click on the next one you accidentally drag the mouse just as you click (left part of screenshot) and it drags all selected files.  This then creates copies of as many files as you had selected, with the names of the new files all prepended by "Copy of " (right part of screenshot).
.That being the case, unless the behaviour differs between Windows versions, surely your file search will have to be for the prepended "copy of" in the file names:
"Copy of *.*"    or    "Copy of *.cr2"
and not the word "copy" appended to the file names:
 "*copy.*"     or    "*copy.cr2"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.