Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I am using Timidity to convert a lot of midi files to mp3. I was wondering if there is a standard way of specifying a output pattern so that it converts all the *.mid files to /path/*.wav

I ask this in general because it would also be the case in a mv command. Or is this tied to a specific implementation in the app?

So, how to move a *.mid files to *.wav ?

share|improve this question

migrated from Oct 20 '11 at 14:17

This question came from our site for professional and enthusiast programmers.

In the case of mv command, have you seen mmv – rrehbein Oct 20 '11 at 15:03
up vote 1 down vote accepted

Suppose you just wanted to rename files. Then if you are using a Bourne shell (such as sh, bash) you can run the command on files matching a pattern using a for loop. Here are equivalent multiline and single-line versions:

for f in *.mid
    mv "$f" "${f%.mid}.wav"
for f in *.mid; do mv "$f" "${f%.mid}.wav"; done

The for loop runs the commands with $f being each word in the expansion of *.mid, and ${f%.mid} removes the suffix .mid so that we can replace it with .wav. The quotes make this program correct for filenames containing spaces (but not filenames starting with "-", as that depends on the command). If you want to match several groups of files rather than everything, you can use multiple patterns like for f in alpha-*.mid beta-*.mid; do ...

You can use any command you want in place of mv. I took a look at Timidity's man page, but I couldn't figure out where it takes an output filename so I haven't given an example.

share|improve this answer

I made a python script that moves *.mid to *.wav.


import sys
import glob
import shutil
import os

    dir = sys.argv[1]
except IndexError:
    print "Usage: "+sys.argv[0]+" dir"
    print "Example: "+sys.argv[0]+" /home/user/dir"

for file in glob.glob(os.path.join(dir, '*.mid')):
    newfile = file.partition(".mid")
    newfile = newfile[0]
    newfile = newfile+".wav"
    shutil.move(file, newfile)
share|improve this answer
This doesn't generalize to performing operations other than renaming as Peterdk wants. – Kevin Reid Oct 21 '11 at 1:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .