Python Forum
Retrieving last 20 file paths from directory
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieving last 20 file paths from directory
#2
Use code tags Code Tags.
Could do it like this.
import glob
import os
from pathlib import Path

path = (r'\\directory')
files = filter(lambda filepath: filepath.is_file(), Path(path).glob('*'))
file_lst = [f for f in files][-20:]
for file in file_lst:
    print(file)
Reply


Messages In This Thread
RE: Retrieving last 20 file paths from directory - by snippsat - Sep-23-2021, 08:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to solve the 'NO SUCH DIRECTORY OR FILE' in pandas, python MohammedSohail 10 15,818 May-08-2020, 07:45 AM
Last Post: nnk
  paths Scott 13 8,345 May-16-2018, 06:25 AM
Last Post: Scott

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020