Removing files with same name and different extension

1

1

I have a large music collection. It is organized in the following structure: artist / album / trackTitle.

Over the course of time, in some directories, I have duplicate-ish files; most of my files are mp3s, but some of them are also converted to mp4s (in the same directory), which I see as duplicates now. I would like to get rid of them - they have the same file name, different extension and newer modified date compared to the originals.

Running Windows 10.

How can I do this without having to go through every folder and manually picking the mp4s for deleting?

Ondrej

Posted 2015-07-31T20:01:17.570

Reputation: 165

2You need to add more information. What operating system are you using, Linux or Windows? What do you mean by not wanting to delete the duplicates *manually*? – geo – 2015-07-31T20:08:36.973

edited the text. – Ondrej – 2015-07-31T20:37:09.320

Updated my answer based on the extra information you've given, – geo – 2015-08-01T21:13:03.217

Answers

2

I'm going to assume that by manually, you mean you don't want to delete them one at a time.

In Windows, you can do this simply by going to the top level of your music file directories and typing:

DEL *.mp4 /S

The '/S' flag deletes files not only in the current directory, but in all sub-directories as well.

In Linux, also from the top directory, you would type:

find . -name '*.mp4' -exec /usr/bin/rm '{}' \;

Use the full path to 'rm' so that you don't wind up using an alias such as 'rm -i'. Also, the braces are in quotes in case you have file names with spaces in them.


OK, so the OS is Windows, and it's possible that the MP4's are the only version of a track, in which case we don't want to delete it.

Given that, deduplicate.bat would look like:

@ECHO OFF

FOR /F "usebackq delims=" %%i in ( `dir /b /s *.mp4` ) do (
    IF EXIST "%%~dpni.mp3" (
        DEL "%%i"
    )
)

That is, do a recursive directory listing of all MP4 files. For each MP4 file found, check to see if there exists a corresponding MP3 file. This is done by combining

  1. %%~di The drive letter
  2. %%~pi The file path
  3. %%~ni The file name, excluding the extension

into %%~dpni and then adding the ".mp3" extension. By doing this, we're guaranteeing that the MP4 and MP3 files, if they both exist, are in the same directory, taking care of the issue you brought up in your comment above of an MP3 file of a given name and an MP4 file of the same name, but in a different directory.

So, if the MP3 file exists, then the MP4 file is a duplicate, and can be safely deleted.

And, for completeness sake...

Notes

  • The quotes are required around the entire file name structure in case there are spaces in the name.
  • The doubled percent signs are because they're in a file. If you were to type this into a console window, then each instance of "%%" would become a single '%'.

geo

Posted 2015-07-31T20:01:17.570

Reputation: 557

yes, I know that of course, but I do not want to do that since some of my not-duplicated songs are mp4, so I somehow need to condition the deletion by the file being a duplicate of mp3 – Ondrej – 2015-07-31T20:49:36.803

Thanks for the clarification. I'll edit post appropriately. – geo – 2015-07-31T22:19:35.723

That BAT sounds great! but it gives me "File not found" and I'm not too good with batches... – Ondrej – 2015-08-03T19:14:20.987

@Ondrej, sorry I didn't see this sooner. So, did you copy this exactly? I ran a test and couldn't get this to fail. Of course, that's meaningless! If it failed for you then it failed! Can you send some sort of example? – geo – 2015-08-17T03:25:30.393

0

Did you try any duplicate file removal tools?, I would recommend this software called dupeGuru music edition. It supports Windows, Linux and Mac. It can identify similar music files even if its encoded differently. it is a freeware and according to the developers it does not install any unwanted software with it.

link to dupeGuru - http://www.hardcoded.net/dupeguru_me/

Shibu Thannikkunnath

Posted 2015-07-31T20:01:17.570

Reputation: 317

This looks great. One thing though - I didn't find a way to have dupeGuru consider duplicates only within the folder in whch the given file is, so for example, if it finds Intro.mp3 inside a Sountrack folder, it should only look for duplicities for this file inside the Sountract folder. Is this possible? Great application by the way. – Ondrej – 2015-07-31T21:17:40.027