get the latest file in a directory

H

Hank

Hi,

I was wondering what is a quick way to find the latest(last modified
date) file from a directory.

Should I use win32file.GetFileTime and compare PyTime? I don't want to
create a PyHANDLE for every single file in the directory, not if
there's an easier way at least.

Thanks
 
J

Joe Francia

Hank said:
Hi,

I was wondering what is a quick way to find the latest(last modified
date) file from a directory.

Should I use win32file.GetFileTime and compare PyTime? I don't want to
create a PyHANDLE for every single file in the directory, not if
there's an easier way at least.

Look at os.stat() and the stat module, along with os.listdir().
 
T

Tim Golden

Hi,

I was wondering what is a quick way to find the latest(last modified
date) file from a directory.

Should I use win32file.GetFileTime and compare PyTime? I don't want to
create a PyHANDLE for every single file in the directory, not if
there's an easier way at least.

Thanks

Given that you're talking about win32file etc. I assume you're on
Windows, so the following (slightly unorthodox) suggestion might help:

import os

files = os.popen (r"dir /od /b *.*").read ().splitlines ()
# dir /od /a-d /b # to avoid directories
files[-1]

TJG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top