I have a blended music library with both “mp3” files and “m4a” files. Many of the music directories and specific album sub directories actually include what appears to duplicate music song files differing only by the file extension of both mp3 and m4a files.
For those directories that contain the same songs with both extensions, how can I use Windows 7 and/or a batch file command to search through my entire music directory (and respective sub directories) and delete only those m4a files where the same song file exists in the mp3 file format in the same music library folder as well?
My music library contains about 75,000 songs if I ignore the duplicate m4a files of the same song that may exist in the same music folder(s) of various albums.
However, right now, with no regard to specific file extension types, my directory appears to have over 100,000 songs (where obviously 25,000 of these songs are duplicates that account for these aforementioned file formats of the same song(s) coexisting in their given respective music album folder and/or music sub directory(ies)).
What operation or command can I use to safely scan my music library and remove extraneous “m4a” song files where the preferred “mp3” files already exist?…While KEEPING those m4a files where NO same song mp3 files already exist?
I also need step by step instructions on how to setup and start any batch files that achieves the stated goal above. Thanks so much Guys!
Best Answer
Here’s a script (a.k.a. a “batch file”) that will do it for you in case you don’t want to download a program from somewhere:
Interpretation:
for %%letter in (wildcard) do some_command
scans the current directory for files matching the wildcard and executes the command with the variable identified by theletter
set to the filename.for /r %%letter in ...
is the same but recursive.(
…)
lets you specify a block of commands instead of just one.%%F
is the name of the M4A file that was found.%%~dpnF
is the drive letter, path, and (base) name parts of%%F
–– i.e., all but the extension. To this we append an.mp3
extension; i.e., a filename that is the same as%%F
except it has an.mp3
extension. Assign this name to themp3name
variable.(
…)
to specify a block of commands.)fc/b %%F !mp3name! > nul
––fc
is file compare.fc
likes to compare text files, so we sayfc/b
to do a binary comparison. Sofc/b %%F !mp3name!
compares the two files.> nul
means don’t display the results of the comparison on the screen; we only want the script to know the result of the comparison.if errorlevel 1
means do the following command(s) only if the immediately preceding command “failed”. In the case offc
, “failure” means that the files were not identical, so we have the script tell you thatHey_Jude.mp3
andHey_Jude.m4a
both exist but are not identical.DEL %%F
means delete the file. (echo DEL %%F
means display the delete command, but do not execute it.)Setup:
.txt
) file to have a.bat
extension. Ignore the warning; click on “Yes”.cd
to the above directory. Type the name of the script (batch) file (you may type the.bat
extension, but you probably don’t need to). Verify that the list ofDEL
commands it reports looks reasonable. If it does,.bat
file, and select Edit.echo DEL
toDEL
. Save and exit.