import os

文件夹路径

folder_path = input('请输入文件路径:')

获取文件列表

files = os.listdir(folder_path)

判断文件列表是否为空

if not files: print('文件夹中没有文件') else: # 遍历文件并计算ed2k for file in files: # 判断是否是文件 if os.path.isfile(os.path.join(folder_path, file)): # 执行rhash命令获取ed2k command = 'rhash -L ' + os.path.join(folder_path, file) result = os.popen(command).read()

        # 解析ed2k
        ed2k_line = result.split('

')[1] ed2k = ed2k_line.split(' ')[1]

        # 输出文件名和ed2k
        print(file, ed2k)
Python3 代码报错 'IndexError: list index out of range'  解决方法

原文地址: https://www.cveoy.top/t/topic/mCj8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录