#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    74
    Rep Power
    12

    Easy question why no IsEmpty(dir)?


    Hi,

    Really easy question but I can't figure it out. How to figure out if directory is empty or not? I thought there should be a IsEmpty method somewhere? Could somebody give me a hint please.

    Thanks
    Random
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,625
    Rep Power
    4247
    You could always use os.listdir() and see if anything is returned. If nothing is returned, the dir is empty.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Another thing is that in python ( correct me if im wrong ) empty strings usualy return false... or you can use the filter function to compare your strings
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Just to expand on what was said here.. there is no IsEmpty in Python for a very simple reason, this is that any empty Python object i.e. an empty string, list, dict or any object that returns one of these values or None, is considered False. Kinda like having IsEmpty built into every single object!

    Which helps keep your programs smaller and much cleaner in typical Python style

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    74
    Rep Power
    12
    Thanks for your help.

IMN logo majestic logo threadwatch logo seochat tools logo