Re: Simple dos Batch Script


[ Follow Ups ] [ Post Followup ] [ The EasyDOS Forum ] [ FAQ ]

Posted by 20080425 on April 25, 2008 at 02:06:43:

In Reply to: Simple dos Batch Script posted by brent on April 24, 2008 at 20:50:35:

: 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 %%f

: I 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

##

All you really need is the following single command, (no batch file necessary), within the directory containing your .mxm and .mp3 files:

for /f "tokens=1,2 delims=." %a in ('dir *.mxm /b /a-d') do if not exist %a.mp3 del %a.mxm


If you want that line in a batch file, change all the single percent signs ("%") to double percent signs ("%%"), like so:

for /f "tokens=1,2 delims=." %%a in ('dir *.mxm /b /a-d') do if not exist %%a.mp3 del %%a.mxm


Follow Ups:



Post a Followup (use TAB key to move between boxes - NOT ENTER or RETURN)

Name:
E-Mail:

Subject:

Type your comments in the box below and SUBMIT:


[ Follow Ups ] [ Post Followup ] [ The EasyDOS Forum ] [ FAQ ]