Deleting empty folders.
Gerrit Holl
gerrit at nl.linux.org
Fri Feb 7 11:01:22 EST 2003
keithk schreef op vrijdag 7 februari om 16:26:31 +0000:
>
> Hi All,
>
> I want to write a short script that checks whether a set of windows
> folders is empty and then if they are , delete them, I am unable to find
> a module in python which checks whether a folder is empty, could someone
> please point me in the right direction,
Use os.listdir:
>>> os.listdir('/tmp/a')
[]
>>> os.listdir('/tmp/b')
['c']
>>> print os.listdir.__doc__
listdir(path) -> list_of_strings
Return a list containing the names of the entries in the directory.
path: path of directory to list
The list is in arbitrary order. It does not include the special
entries '.' and '..' even if they are present in the directory.
http://www.python.org/dev/doc/devel/lib/os-file-dir.html
yours,
Gerrit.
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/
More information about the Python-list
mailing list