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

Neil Schemenauer nas at python.ca
Thu Feb 21 02:00:18 CET 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")

Cheers,

  Neil




More information about the Python-list mailing list