我的文件夹中有许多文件,其名称遵循以下约定:
0.1.txt, 0.15.txt, 0.2.txt, 0.25.txt, 0.3.txt, ...
我需要一一阅读它们并处理其中的数据。目前,我使用以下命令打开每个文件:
import os
# This is the path where all the files are stored.
folder path = '/home/user/some_folder/'
# Open one of the files,
for data_file in os.listdir(folder_path):
...
不幸的是,这将以不特定的顺序读取文件(不确定如何选择它们),我需要从文件名最小的文件开始读取文件,然后再从文件号开始立即读取,以此类推,直到最后一个文件。 。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句