2011-10-29 52 views
0

我想在工作目录中将所有FLAC文件转换为OGG:Python批量转换FLAC文件

这就是我已经拥有的。

for root, dirs, files in os.walk(args): 
     flacs = [f for f in files if f.endswith('.flac')] 
     oggs = [o for o in files if o.endswith('.ogg')] 

     for flacfiles in flacs: 
      id3 = ('id3v2', '-C', flacfiles) 
      cmd = ('oggenc', '-q7', flacfiles) 
      try: 
       subprocess.check_call(id3, cwd=root) 
       subprocess.check_call(cmd, cwd=root) 
      except subprocess.CalledProcessError: 
       print "subprocess.CalledProcessError: Command %s returned non-zero exit status 1" % cwd 

现在我想知道我怎么能 - 包含我的FLAC文件的目录 - 检查是否有一个.FLAC与.CUE,如果这是do_something)的情况下(

+2

另请考虑[GNU Make](http://www.gnu.org/s/make/)。它特别为解决这些任务而开发。使用[这个Makefile](http://www.mat.univie.ac.at/~eno/Makefile.f2o),你可以检测已经转换的文件,并行启动多个转换器进程的能力以及更多! – Kirill

回答

0
for flacfiles in flacs: 
    if os.path.exists(os.path.splitext(flacfiles)[0] + '.cue')): 
     # do something 
+0

获取:TypeError:强制转换为Unicode:需要字符串或缓冲区,找到元组 –