Python 希伯来输入\文件系统格式
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 XP SP2。
提前谢谢你,
Liron。
1 个回答
0
只需要用 os.listdir(unicode(str))
来代替 os.listdir(str)
,这样可以确保字符串是Unicode格式的,否则程序会出错。
类似的问题可以在 这个链接 找到。