Re: How to determine that if a folder is empty?

2005-08-09 Thread Scott David Daniels
could ildg wrote: > I want to know this because I want to zip a directory and all of its > sub-files and sub-directories to a zip file. zipfile module of python > will not automatically include the empty directories, so I have to > check if a dir is empty and do this manually Can you make work

Re: How to determine that if a folder is empty?

2005-08-09 Thread Peter Hansen
could ildg wrote: > On 8/8/05, Peter Hansen <[EMAIL PROTECTED]> wrote: >>could ildg wrote: >>>I want to check if a folder named "foldername" is empty. >>>I use os.listdir(foldername)==[] to do this, >>>but it will be very slow if the folder has a lot of sub-files. >>>Is there any efficient ways to

Re: How to determine that if a folder is empty?

2005-08-08 Thread could ildg
On 8/8/05, Peter Hansen <[EMAIL PROTECTED]> wrote: > could ildg wrote: > > I want to check if a folder named "foldername" is empty. > > I use os.listdir(foldername)==[] to do this, > > but it will be very slow if the folder has a lot of sub-files. > > Is there any efficient ways to do this? > > I'

Re: How to determine that if a folder is empty?

2005-08-08 Thread David Cuthbert
Mike Meyer wrote: > Just out of curiosity, is there an OS out there where you can have the > permissions needed to delete a directory without having the > permissions needed to create it appropriately? Not an OS, but AFS has a wider set of permissions (RLIDWKA - which, if I remember correctly, ar

Re: How to determine that if a folder is empty?

2005-08-08 Thread Bernhard Herzog
[EMAIL PROTECTED] writes: > On standard Unix fileystems, one way to check for this is to check that the > st_nlink of the directory is 2. In that case you only know that the directory doesn't have any subdirectories. It may still contain ordinary files and other non-directories. Bernhard -

Re: How to determine that if a folder is empty?

2005-08-08 Thread Dan Sommers
On Mon, 08 Aug 2005 09:03:39 -0400, Mike Meyer <[EMAIL PROTECTED]> wrote: > Just out of curiosity, is there an OS out there where you can have the > permissions needed to delete a directory without having the > permissions needed to create it appropriately? Depending on your definition of "out th

Re: How to determine that if a folder is empty?

2005-08-08 Thread Mike Meyer
James Dennett <[EMAIL PROTECTED]> writes: > Reinhold Birkenfeld wrote: > >> could ildg wrote: >> >>>I want to check if a folder named "foldername" is empty. >>>I use os.listdir(foldername)==[] to do this, >>>but it will be very slow if the folder has a lot of sub-files. >>>Is there any efficient wa

Re: How to determine that if a folder is empty?

2005-08-08 Thread Peter Hansen
could ildg wrote: > I want to check if a folder named "foldername" is empty. > I use os.listdir(foldername)==[] to do this, > but it will be very slow if the folder has a lot of sub-files. > Is there any efficient ways to do this? I'm just curious to know under what circumstances where it's import

Re: How to determine that if a folder is empty?

2005-08-08 Thread John Machin
Reinhold Birkenfeld wrote: > could ildg wrote: > >>I want to check if a folder named "foldername" is empty. >>I use os.listdir(foldername)==[] to do this, >>but it will be very slow if the folder has a lot of sub-files. >>Is there any efficient ways to do this? > > > try: > os.rmdir(path) >

Re: How to determine that if a folder is empty?

2005-08-08 Thread jepler
On standard Unix fileystems, one way to check for this is to check that the st_nlink of the directory is 2. However, even on Unix systems this isn't guaranteed for all filesystem types. Of course, finding whether a directory is empty is inherently racy: a file could be created between the time yo

Re: How to determine that if a folder is empty?

2005-08-08 Thread Neil Hodgson
could ildg > so you mean that this is not platform-independent? Your existing code is platform-independent but I think for faster code you will need to write platform-dependent code. FindFirstFile is only available on Windows. Neil -- http://mail.python.org/mailman/listinfo/python-lis

Re: How to determine that if a folder is empty?

2005-08-08 Thread James Dennett
Reinhold Birkenfeld wrote: > could ildg wrote: > >>I want to check if a folder named "foldername" is empty. >>I use os.listdir(foldername)==[] to do this, >>but it will be very slow if the folder has a lot of sub-files. >>Is there any efficient ways to do this? > > > try: > os.rmdir(path) >

Re: How to determine that if a folder is empty?

2005-08-08 Thread Reinhold Birkenfeld
could ildg wrote: > I want to check if a folder named "foldername" is empty. > I use os.listdir(foldername)==[] to do this, > but it will be very slow if the folder has a lot of sub-files. > Is there any efficient ways to do this? try: os.rmdir(path) empty = True except OSError: empty

Re: How to determine that if a folder is empty?

2005-08-07 Thread could ildg
Thank you . so you mean that this is not platform-independent? On 8/8/05, Neil Hodgson <[EMAIL PROTECTED]> wrote: > could ildg: > > > I want to check if a folder named "foldername" is empty. > > I use os.listdir(foldername)==[] to do this, > > but it will be very slow if the folder has a lot of s

Re: How to determine that if a folder is empty?

2005-08-07 Thread Neil Hodgson
could ildg: > I want to check if a folder named "foldername" is empty. > I use os.listdir(foldername)==[] to do this, > but it will be very slow if the folder has a lot of sub-files. > Is there any efficient ways to do this? The first thing to do is measure the performance of this operation

How to determine that if a folder is empty?

2005-08-07 Thread could ildg
I want to check if a folder named "foldername" is empty. I use os.listdir(foldername)==[] to do this, but it will be very slow if the folder has a lot of sub-files. Is there any efficient ways to do this? Thanks~ -- http://mail.python.org/mailman/listinfo/python-list