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
Who is Participating?
BillDLConnect With a Mentor Commented:
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
cd %userprofile%\pictures
del "*copy.*" /s

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.
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
cd %userprofile%\pictures
del "*copy.jpg" /s
del "*copy.png" /s
del "*copy.bmp" /s
del "*copy.gif" /s

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 ( 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?
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.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

KCTSAuthor Commented:
I was rather looking for a script which deleted files with the word COPY in the filename .
KCTSAuthor 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.
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"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.