python 希伯来语输入\文件系统格式

发布于 2024-08-17 06:53:47 字数 1255 浏览 7 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

写给空气的情书 2024-08-24 06:53:47

只需使用 os.listdir(unicode(str)) 代替 os.listdir(str) 即可确保 str 是 Unicode,否则将会失败。

这个问题上可以找到同样的问题

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文