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
#1
Hello all,

I'm having a hard time getting this script across the finish line. I want to display only the last 20 file paths in the given directory, but I keep hitting a wall. Right now, it prints all the file paths in the folder, but I only want to the last 20. Can anyone help point me in the right direction?

import glob
import os
from pathlib import Path
path = (r'\\directory')
files = filter(lambda filepath: filepath.is_file(), Path(path).glob('*'))
for file in files:
   print(file.absolute())
Yoriz write Sep-24-2021, 01:09 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Retrieving last 20 file paths from directory - by dyerlee91 - Sep-23-2021, 04:46 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,599 May-08-2020, 07:45 AM
Last Post: nnk
  paths Scott 13 8,221 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