Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm fairly certain this can be done (simply), but it's been years since I wrote a batch file, and I'm scared I'll screw things up and end up deleting all the files on my HD
Here's what I'm trying to accomplish.
I have a directory of audio files (.mp3), and a program I use writes a plot file for each audio file (it's an .mxm file).
When you rename an audio file, it will create a new .mxm file, but it leaves behind the old .mxm file. The orphaned .mxm is no longer needed and in fact kinda makes a mess things.
I'm trying to find a simple batch file (or even a shareware program) that will:
1. Look at all the files within a directory that have an extension of .mxm
2. See if, within that directory, there is a matching .mp3 file (where the filename of the .mp3 is the exact same filename of the .mxm file)
3. If there is a matching .mp3 to the .mxm, then go to the next .mxm file and look for a .mp3, etc ...
4. If there is NO matching .mp3 to the .mxm, then delete the unneeded .mxm file then move to the next .mxm for a comparison.
5. Hopefully have the batch file end once all the .mxm files are compared (but if it starts at the top of the directory again and runs in a continuous loop, I can always stop that manually.
6. I've tried using this code with no luck. I think it's because these are long file names, not DOS 8.3 file names.
@ echo off
for %%f in (*.mxm) do if not exist %%~nf.mp3 del %%fI certainly don't mind if someone wants to give me some instructions as to how to go about writing such a batch file. I'll be glad to do it. But I figure it will probably be easier and quicker for someone to throw together a quickie batch file and just be done with it.
Either way, I sure appreciate anyone's help.
Thanks

@echo off
setLocal EnableDelayedExpansionpushd o:\music
for /f "tokens=* delims= " %%a in ('dir/b *.mxm') do (
if not exist %%~Na.mp3 echo del %%a
)
=====================================
If at first you don't succeed, you're about average.M2

M2:
Thanks.
It's --almost-- working.I changed the path (pushd o:\music) to an actual folder (pushd m:\dance\new), and I watched as the batch file ran. Since there are a large number of files in that directory, most of it scrolled off. But the tail end of the output remained. The files it needs to delete are identified correctly. And the files --look-- like they should be deleted. But they aren't.
Could it be there needs to be an echo of "y" or something?
To give you an example of what's happening, I've moved 5 mp3s to a temporary folder, and 10 mxm files to that same temporary folder.
The output of the file is below.
If the wrapping makes it too difficult to read, you can view it here:
http://rapidshare.com/files/1102213...I really appreciate the help.
-- Thanks
-- Brent
M:\temp>dir *.mp3
Volume in drive M is MP3s
Volume Serial Number is 152E-651CDirectory of M:\temp
04/19/2008 01:49 AM 8,795,331 2 4 grooves - the way i do (original club
mix).mp3
04/19/2008 01:49 AM 5,158,060 2 4 grooves - the way i do (original radi
o mix).mp3
04/19/2008 01:49 AM 5,630,294 2 pac - how do you want it.mp3
04/19/2008 01:50 AM 12,232,191 7th heaven & ann - marie smith (7th heave
n vocal mix).mp3
04/19/2008 01:50 AM 11,871,014 abel ramos - electro fun (matt correa rmx
).mp3
5 File(s) 43,686,890 bytes
0 Dir(s) 87,654,711,296 bytes freeM:\temp>dir *.mxm
Volume in drive M is MP3s
Volume Serial Number is 152E-651CDirectory of M:\temp
04/17/2008 01:31 AM 112,692 1 of & ryo - so fast (andrea bertolini rm
x).mxm
04/18/2008 04:44 PM 113,110 1gnition - secret sunday lover (dj sing &
marcus j knight sydney rmx).mxm
04/18/2008 04:44 PM 110,040 2 4 grooves - the way i do (club mix).mxm04/18/2008 04:44 PM 110,272 2 4 grooves - the way i do (original club
mix).mxm
04/18/2008 04:44 PM 71,542 2 4 grooves - the way i do (original radi
o mix).mxm
04/18/2008 04:43 PM 114,118 2 4 grooves - the way i do (sunloverz rmx
).mxm
04/18/2008 04:43 PM 120,020 2 4 grooves - the way i do (the real boot
y babes rmx).mxm
04/18/2008 04:42 PM 171,710 2 4 grooves - the way i do (tribal - elec
tro club mix).mxm
04/18/2008 04:42 PM 105,846 2 4 grooves - wanna dance 2nd rmx.mxm
04/18/2008 04:42 PM 86,922 2 bit pie - here i come (album version).m
xm
10 File(s) 1,116,272 bytes
0 Dir(s) 87,654,711,296 bytes freeM:\temp>clean.bat
del "1 of & ryo - so fast (andrea bertolini rmx).mxm"
del "1gnition - secret sunday lover (dj sing & marcus j knight sydney rmx).mxm"
del "2 4 grooves - the way i do (club mix).mxm"
del "2 4 grooves - the way i do (sunloverz rmx).mxm"
del "2 4 grooves - the way i do (the real booty babes rmx).mxm"
del "2 4 grooves - the way i do (tribal - electro club mix).mxm"
del "2 4 grooves - wanna dance 2nd rmx.mxm"
del "2 bit pie - here i come (album version).mxm"M:\temp>dir *.mxm
Volume in drive M is MP3s
Volume Serial Number is 152E-651CDirectory of M:\temp
04/17/2008 01:31 AM 112,692 1 of & ryo - so fast (andrea bertolini rm
x).mxm
04/18/2008 04:44 PM 113,110 1gnition - secret sunday lover (dj sing &
marcus j knight sydney rmx).mxm
04/18/2008 04:44 PM 110,040 2 4 grooves - the way i do (club mix).mxm04/18/2008 04:44 PM 110,272 2 4 grooves - the way i do (original club
mix).mxm
04/18/2008 04:44 PM 71,542 2 4 grooves - the way i do (original radi
o mix).mxm
04/18/2008 04:43 PM 114,118 2 4 grooves - the way i do (sunloverz rmx
).mxm
04/18/2008 04:43 PM 120,020 2 4 grooves - the way i do (the real boot
y babes rmx).mxm
04/18/2008 04:42 PM 171,710 2 4 grooves - the way i do (tribal - elec
tro club mix).mxm
04/18/2008 04:42 PM 105,846 2 4 grooves - wanna dance 2nd rmx.mxm
04/18/2008 04:42 PM 86,922 2 bit pie - here i come (album version).m
xm
10 File(s) 1,116,272 bytes
0 Dir(s) 87,654,711,296 bytes freeM:\temp>

As written, it doesn't delete anything. That's for safety. When you're satisfied, remove the ECHO before the DEL.
=====================================
If at first you don't succeed, you're about average.M2

Geez, I feel so dumb.
Obvious. Very obvious.
Thank you SO MUCH !
That did it perfectly.
Thanks for the extra safety.
Nice touch.
-- Brent

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |