79271084

Date: 2024-12-11 09:09:35
Score: 0.5
Natty:
Report link

For those who came here looking for a solution to get the first file in a dir, using pathlib

import pathlib

my_dir = pathlib.Path("my/dir/")
first_file = next((x for x in my_dir.iterdir() if x.is_file()), None)

first_file is None if dir is empty

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Er...