查找文件夹中的下一个文件

问题描述 投票:0回答:1

我获取文件夹中下一个文件的名称的方法很糟糕,但是可以。我想删除调用os.listdir函数的要求,因为在大型文件夹中它很慢,但是不知道如何。欢迎任何帮助。

注意:Fullpathtoimagefile是旧文件changeimage是获取下一个文件的函数的名称

def nextfile(self):
    folder, filename = os.path.split(fullpathtoimagefile)
    filelist = os.listdir(folder)
    nextfile = filelist.index(filename) + 1
    nextfilename = filelist[nextfile]
    changeimage(os.path.join(folder, nextfilename))

tl; dr获得文件夹中下一个文件的全名的更有效方法

python performance file directory os.path
1个回答
0
投票

也许您可以解决这一问题。

© www.soinside.com 2019 - 2024. All rights reserved.