jborean93 / smbprotocol

Python SMBv2 and v3 Client
MIT License
320 stars 74 forks source link

Any way of getting the most recently modified files and directories ? #134

Closed ghost closed 3 years ago

jborean93 commented 3 years ago

AFAIK there isn't a builtin way to sort as you request the dir contents so you would have to do this after you've retrieved it all. Essentially

import smbclient

entries = sorted(
    smbclient.scandir(r"\\server\share\dir"),
    key=lambda e: e.stat().st_mtime,
    reverse=True
)

That will give you the directory listing that is sorted by st_mtime which is the number of seconds since EPOCH (1970-01-01). Have a look at sorting for more details.