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 XPS p2。 提前致谢, 利隆.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用 os.listdir(unicode(str)) 代替 os.listdir(str) 即可确保 str 是 Unicode,否则将会失败。
在这个问题上可以找到同样的问题
Just use
os.listdir(unicode(str))
instead ofos.listdir(str)
in order to be sure that str is Unicode, otherwise it will just fail.Same problem can be found on this question