views:

60

answers:

2
import os
import pprint
import subprocess
def  Convert (dir):
    curDir = dir
    pathToBonk = "C:\\Program Files\\BonkEnc\\becmd.exe" #Where the becmd.exe file lives
    problemFiles = [] #A list of files that failed conversion
    #
    for item in os.listdir(curDir):
        if item.upper().endswith('.M4A'):
            fullPath = os.path.join(curDir,item)
            cmd = '"%s" -e LAME -d "%s" "%s"' #The command to convert a single file
            cmd = cmd % (pathToBonk, curDir, fullPath)
            val = subprocess.call(cmd)
            if val == 0: #Successfull conversion, delete the original
                os.remove(fullPath)
            else:
                problemFiles.append(fullPath)
                print 'Problem converting %s' % item
                os.rename(fullPath, fullPath + ".BAD")
    print 'These files had problems converting and have been renamed with .BAD extensions:'
    pprint.pprint(problemFiles)     

var = raw_input("Insert Path: ")
var.decode("iso-8859-8")
Convert(var)

Hi There, I want to reformat my music from .m4a into mp3 songs. i use the bonkenc command line.

The problem is that some of my folders are in Hebrew. When I use this script in folders which doesn't contain hebrew - It works flawlessly. but when there's Hebrew in the path- the scrpit doesn't work.

I tried encoding\deconding the hebrew, but nothing helped.

I run windows xps p2. Thanks in advance, Liron.

+1  A: 

see: http://stackoverflow.com/questions/497233/pythons-os-path-choking-on-hebrew-filenames

Oren
yep. but It sometimes throws an exception I couldn't catch.
Liron Tal
+1  A: 

Just use os.listdir(unicode(str)) instead of os.listdir(str) in order to be sure that str is Unicode, otherwise it will just fail.

Same problem can be found on this question

Sorin Sbarnea