How do you conver output of "popen('ls')" to a list?

Neil Schemenauer nas at
Wed Feb 20 20:00:18 EST 2002

husam wrote:
> os.listdir('.') gets you all the files in the '.' dircetory. This want
> work if i want to process some selected files. In contrast to this,
> "os.popen() allows you to pass arguments like "ls *txt" to retrieve only
> *.txt files.

Sorry, that's still not a good argument for two forks and god knows how
any system calls.  Try this:

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



More information about the Python-list mailing list