Python Forum
deleting an empty Dir, using pathlib.Path
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
deleting an empty Dir, using pathlib.Path
#10
I suggest this
import os

def bool_dir(path):
    """Convert directory to bool. A directory is False iff it is empty.

    Raise OSError if path is not a directory."""
    with os.scandir(path) as it:
        return bool(next(it, False))
tester_V likes this post
Reply


Messages In This Thread
RE: deleting an empty Dir, using pathlib.Path - by Gribouillis - Jul-01-2021, 01:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  -i option changes sys.path (removes leading empty string '') markanth 6 2,111 Aug-26-2022, 09:27 PM
Last Post: markanth
  Pathlib import not working chriswrcg 9 3,996 May-29-2022, 07:37 PM
Last Post: snippsat
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,280 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Trying to pathlib instead of os.path tester_V 4 2,596 Jun-22-2021, 04:15 AM
Last Post: tester_V
  pathlib destpath.exists() true even file does not exist NaN 9 4,797 Dec-01-2020, 12:43 PM
Last Post: NaN
  Question about if with () or without () / pathlib Tecuma 3 2,309 Apr-02-2020, 10:02 AM
Last Post: Tecuma
  pathlib hanging bluefrog 2 3,223 Sep-25-2018, 12:59 PM
Last Post: volcano63
  pathlib: resolving a path that does not exist Skaperen 6 5,671 Sep-08-2018, 12:25 AM
Last Post: Skaperen
  makin hardlinks with pathlib.Path Skaperen 2 5,317 Sep-06-2018, 07:53 AM
Last Post: scidam
  Need help using pathlib to read text file into dictionary gwilli3 4 4,291 Aug-13-2018, 06:21 PM
Last Post: gwilli3

Forum Jump:

User Panel Messages

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