Python 使用getctime()时没有此类文件或目录错误

Python 使用getctime()时没有此类文件或目录错误,python,directory,Python,Directory,我正在尝试使用python查找上次创建的文件夹名称: directory = mx.get_env('WORKDIR')+'/Benchmarks/SPECjvm2008/SPECjvm2008/r‌​esults/' folders = os.walk(directory).next()[1] creation_times = [(folder, os.path.getctime(folder)) for folder in folders] creation_times.sort(key=l

我正在尝试使用python查找上次创建的文件夹名称:

directory = mx.get_env('WORKDIR')+'/Benchmarks/SPECjvm2008/SPECjvm2008/r‌​esults/'
folders = os.walk(directory).next()[1]
creation_times = [(folder, os.path.getctime(folder)) for folder in folders]
creation_times.sort(key=lambda x: x[1])  # sort by creation time
但我得到了以下错误:

文件“/home/taleporos/.jenkins/workspace/MaxineBench/graal/mxtool/mx.py”,第3588行,在
main()
文件“/home/taleporos/.jenkins/workspace/MaxineBench/graal/mxtool/mx.py”,主文件第3577行
retcode=c(命令参数)
SPECJVM中的文件“/home/taleporos/.jenkins/workspace/MaxineBench/maxine/mxmaxine/commands.py”,第432行
dirfinder('specjvm')
文件“/home/taleporos/.jenkins/workspace/MaxineBench/maxine/mxmaxine/commands.py”,第394行,在dirfinder中
为文件夹中的文件夹打印“文件夹:”,[(文件夹,os.path.getctime(文件夹))]
getctime中的文件“/usr/lib/python2.7/genericpath.py”,第72行
返回os.stat(filename).st\u-ctime
OSError:[Errno 2]没有这样的文件或目录:“SPECjvm2008.002”

只需添加整个路径:

creation_times = [(folder, os.path.getctime(directory+folder)) for folder in folders]
creation_times.sort(key=lambda x: x[1])  # sort by creation time

使用绝对路径。
os.path.getctime(文件夹)
->
os.path.getctime(目录+文件夹)
错误消息不包括您显示的任何代码行。错误与其他文件无关,因此我没有添加它们。它只需要绝对路径。谢谢m8s