Python get most recent file in a directory with certain extension

前端 未结 1 1608
一整个雨季
一整个雨季 2021-02-05 13:02

I\'m trying to use the newest file in the \'upload\' directory with \'.log\' extension to be processed by Python. I use a Ubuntu web server and file upload is done

1条回答
  •  遥遥无期
    2021-02-05 13:25

    The problem is that the logical inverse of max is min:

    newest = max(glob.iglob('upload/*.log'), key=os.path.getctime)
    

    For your purposes should be:

     newest = min(glob.iglob('upload/*.log'), key=os.path.getctime)
    

    0 讨论(0)
提交回复
热议问题