Python oggenc script
<p>I want to write a python script (Yes not Bash) that will use flac files and encode them using oggenc and then on successful encoding delete the flac file.</p>

<p>So far I have this:</p>

<pre><code>import os, sys
import fnmatch

command = 'oggenc -q7 *.flac'

def main():
    for root, dirs, files in os.walk('/home/wagnerf/test'):
        for name in files:
            if fnmatch.fnmatch(name, '*.flac'):
</code></pre>

<p>I kind of wanted to use </p>

<blockquote>
  <p>os.system("bash -c %s" % command)</p>
</blockquote>

<p>after the if but that won't work, say's </p>

<blockquote>
  <p>ERROR: No input files specified. Use -h for help.</p>
</blockquote>

<p>I guess I have to use the name in my command?</p>

<p>EDIT 
My file structure will look somethibg like this:</p>

<pre><code>-- test
   -- test1
     -- test1.flac
     -- test2.flac
   -- test2
     -- test3.flac
     -- test1.flac
</code></pre>

<p>And I want those flac files to be converted to ogg in the same directory, basically I want to automate </p>

<pre><code>cd /somedir/
oggenc -q7 *.flac
cd ..
cd /someotherdir/
oggenc -q7 *.flac
</code></pre>

<p>so that I don't have to always enter the subdirectory!</p>

<p><strong>ANSWER:</strong></p>

<p>@larsmanns Thank you very much, just had to make some adjustments:</p>

<pre><code>from fnmatch import fnmatch
import os, sys
import subprocess

def main():
    for root, dirs, files in os.walk('/home/wagnerf/test'):
        flacs = [f for f in files if fnmatch(f, '*.flac')]
        if flacs:
            for file in flacs:
                cmd = 'oggenc', '-q7', '%s' % file
                subprocess.check_call(cmd, cwd=root)
</code></pre>

<p>flacs returns a list and we need to use oggenc per file so for every tuple do ...
Anyway thanks again the rest is easy!</p>

<p><strong>BTW</strong></p>

<p>I finished the script you can find it here: <a href="https://bitbucket.org/wagnerfelix/tools/src" rel="nofollow">musico</a></p>
