开发者

python hebrew input\filesytem format

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 flawl开发者_运维问答essly. 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜