Read In Directory Contents

bjorn bjorn at roguewave.com
Mon Jan 17 13:17:40 EST 2000


import glob
list = glob.glob("*.txt")

(note that naming a variable list, is generally not a good idea -- it
shadows a builtin)

-- bjorn

Scott Billings wrote:

> For a program I'm working on, it would be very useful if I could use an
> expression such as:
>
> list = os.getcwd() + "*.txt"
>
> to have the names of all text files in the current dir placed into the
> list. However, when I try this method, I get an error about no such file
> existing.
>
> So, how would I go about doing this?
>
> -Scott Billings-
>
> --
> http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list