3
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)

こんにちは。音楽を .m4a から mp3 の曲に再フォーマットしたいと考えています。bonkenc コマンド ラインを使用します。

問題は、フォルダの一部がヘブライ語であることです。ヘブライ語を含まないフォルダーでこのスクリプトを使用すると、問題なく動作します。しかし、パスにヘブライ語がある場合、スクリプトは機能しません。

ヘブライ語のエンコードとデコードを試みましたが、何も役に立ちませんでした。

Windows xps p2 を実行しています。前もってありがとう、ライロン。

4

1 に答える 1

0

str が Unicode であることを確認するためにos.listdir(unicode(str))代わりに使用してください。そうしないと失敗します。os.listdir(str)

同じ問題がこの質問で見つかります

于 2010-01-04T20:05:28.623 に答える