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。 提前致谢, 利龙。
最佳答案
只需使用 os.listdir(unicode(str))
而不是 os.listdir(str)
以确保 str 是 Unicode,否则它只会失败。
同样的问题可以在this question上找到
关于python 希伯来文输入\文件系统格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1993402/