[Tutor] Finding bottom level directories, and command-line arguments
Simon Gerber
nequeo at gmail.com
Wed Feb 8 00:21:50 CET 2006
G'day Tutors,
I watch many different TV shows on my PC, as many of us do. But I am
sick and tired of forgetting which episode I was up to. So, in a
prodigious effort to avoid ever using, say, a pen, I am working on a
script to take over some of my brain's memory handling. When complete,
I will simply be able to type, for example, 'play family_guy' from the
command line and it will automatically launch the next unwatched
episode.
So I was wondering if anyone has an efficient, Pythonesque way of
creating a dictionary of all bottom level directories in a given path.
At the moment I'm doing this \/ to find all directories in a given
directory. But I really want to dig down and find all bottom level
directories.
-------
def build_dir_index():
for item in os.listdir(vid_path):
if os.path.isdir(item):
# Ask user what to do with this directory...
--------
I know about os.walk and os.path.walk, but I'm not sure how to use
them effectively to get a list of all bottom level directories.
Otherwise, I've also considered using the above listdir/isdir
recursively to build up lists of subdirectories, and tag all
directories that return an empty list as bottom-level.
But I just get the feeling there's a simple, elegant way of doing this
that I'm missing.
Second question - anyone have some good pointers/links about how to
parse command line arguments effectively? I.e. perhaps build a
dictionary of all options and their values, so I can deal with them
appropriately?
Cheers,
--
Seen in the release notes for ACPI-support 0.34:
'The "I do not wish to discuss it" release
* Add workaround for prodding fans back into life on resume
* Add sick evil code for doing sick evil things to sick evil
screensavers'
More information about the Tutor
mailing list