Get name of file from directory into variable

loial jldunn2000 at gmail.com
Tue Aug 3 06:41:00 EDT 2010


On 3 Aug, 11:31, Alex Willmer <a... at moreati.org.uk> wrote:
> On Aug 3, 11:21 am, loial <jldunn2... at gmail.com> 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?
>
> Depends if you count imports.
>
> import glob
> my_files = glob.glob('/home/mydir/JOHN*.xml')
>
> Regards, Alex

Cheers



More information about the Python-list mailing list