for folder in sorted(os.listdir(dir_path)): # 按文件名排序后遍历文件夹 if not os.path.isdir(os.path.join(dir_path, folder)): # 如果当前路径不是文件夹,则跳过 continue

        # 遍历当前文件夹内的所有pci文件
        for pci_file in sorted(os.listdir(os.path.join(dir_path, folder))):  # 按文件名排序后遍历pci文件
            if not pci_file.endswith('.pci'):  # 如果该文件不是pci文件,则跳过
                continue

            file_path = os.path.join(dir_path, folder, pci_file)  # 拼接出pci文件的全路径

            # 打开pci文件并读取内容
            with open(file_path, 'rb') as f:
                # ... 处理文件内容 ...
Python 按文件名顺序打开文件夹中的 PCI 文件

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

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