Get name of file from directory into variable

Matteo Landi landimatte at
Tue Aug 3 12:34:43 CEST 2010

I suggest you to take a look at walk function inside the os module
[1]; IIRC, on the list you would find a discussion on how to create a
wrapper for os.walk with support for filters or wildcards.



On Tue, Aug 3, 2010 at 12:21 PM, loial <jldunn2000 at> wrote:
> In a unix shell script I can do something like this to look in a
> directory and get the name of a file or files into a variable :
> MYFILE=`ls /home/mydir/JOHN*.xml`
> Can I do this in one line in python?
> --

Matteo Landi

More information about the Python-list mailing list