Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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. ashisoft.com –  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
add comment

3 Answers

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
add comment

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
add comment

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:

@ECHO OFF
FOR %%A IN (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) DO (DIR /B /S /A-D %%A:\>>FILELIST.TXT) 2>NUL

http://www.ehow.com/how_6926969_remove-files-xp-operating-system.html

share|improve this answer
add comment

Your Answer

 
discard

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.