我有一个名为 test 的文件夹,其中包含 11.txt,12.txt,13.txt
我需要阅读 test 文件夹的内容,找到最大的文本文件名,并将其传递给for循环起始索引:
def find_largest_index(file_path):
txt_files = glob.glob("*.*")
#do smthing here to find the largest filename index
file_path = 'home/Documents/PythonCodeIsHere/test'
i = find_largest_index(file_path)
for page_i in pages_num[i-1:]:
print(page_i)
答案 0 :(得分:1)
import os
filenames = [int(filename[:-4]) for filename in os.listdir(file_path) if ( filename.endswith('.txt') and not filename.startswith('running') )]
i = max(filenames)