Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What I want to do is have a batch file search folders, and subfolders, for matching file names that are ending in .mp3 and .wma and delete or move the *.wma duplicates.

Below you'll find what I have come up with until now, I know it is wrong for at least two reasons. I have searched the internet, and tried a number of things, but now I am stuck. Can anyone please help me with this?

for /r %%f in "(%userprofile%\my music\* - ?.*)" do del "%%f" /s/p
share|improve this question
Why not use a free tool from ashisoft duplicate file finder. – user109612 Dec 14 '11 at 22:12
Because it costs $30.00. the free version will not work on the task I want unless I buy it. I would rather learn how to do it, than throw money at it. But thank you for the tip. – Bringo Dec 16 '11 at 21:28

May I recommend powershell?

cd C:\users\Administrator\Desktop\test\

$Afiles = ls *.text
$Bfiles = ls *.txt

$Alist = @()
$Blist = @()

foreach( $A in $Afiles)
    $Alist += $A.BaseName

foreach( $B in $Bfiles)
    $Blist += $B.BaseName

foreach($A in $Alist)
    if($Blist -contains $a) 
        rm ("$A.text") -WhatIf

while this may seem a bit more complicated, its much more extensible and reusable IMHO.

share|improve this answer

Sorry for brining up that old question, but for anyone who stumbles here in the future, check this out, this works in a batch file:


share|improve this answer

I'm no windows guru but forfiles is pretty straight forward.
forfiles /p "%userprofile%\my music\" /s /m *.mp3 /C "cmd /c del @relpath@fname.wma"

share|improve this answer
I appreciate your response Micke. I am not a guru either. I am actually pretty new at writing batch files. I have written a few easy batch files using the basics, but that is all. I have tried your solution, and I think it is much closer to what I need than what I had. However it did not work. I receive an error as follows, ERROR: Invalid argument/option - '@relpath@fname.wma' I would appreciate any other ideas you may have. Thank you. – Bringo Dec 11 '11 at 0:17
Okay, I got it to kind of work. I input it as: FORFILES /P "%USERPROFILE%\MY MUSIC" /S /M *.MP3 /C "CMD /C DEL @FNAME.WMA" It did not like the "\" behind "my music" or "@relpath" with "@fname" for some reason. It does delete *.wma files that have a duplicate *.mp3 file. However, only the same folder, and not in lateral folders. Any ideas? thank you again for your help. – Bringo Dec 11 '11 at 18:21
Try adding @PATH\ before @FNAME instead of @RELPATH. You want it to expand to the path and the filename plus your extension (.WMA) so DEL can run. I'm not at a Windows computer right now so unfortunately I cannot try it myself. – micke Dec 13 '11 at 22:11
That didn't work, or I typed it incorrectly. It works using @fname by itself, but it only deletes *.WMA files in the current directory where an *.MP3 was found, and not in the rest of the directories. – Bringo Dec 17 '11 at 13:19

this worked really great for what i needed

forfiles /P C:\Projects\QualityPush\ /S /M  first.txt /C "cmd /c echo @path"
forfiles /P C:\Projects\QualityPush\ /S /M  second.txt /C "cmd /c echo @path"

This will give you the path to each file for any matches in sub dirs and keeps them collated together

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.