Re: Get name of file from directory into variable

2010-08-04 Thread Steven W. Orr
On 08/03/10 06:21, quoth loial: > 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? > Sorry, but I just can't help myself. Yeah, it

Re: Get name of file from directory into variable

2010-08-03 Thread Matteo Landi
Ops I miss the "one line" request, so my previous answer was definitely OT. glob seems to be your solution. On Tue, Aug 3, 2010 at 12:44 PM, Rory Campbell-Lange wrote: > On 03/08/10, Alex Willmer (a...@moreati.org.uk) wrote: >> On Aug 3, 11:21?am, loial wrote: >> > In a unix shell script I can

Re: Get name of file from directory into variable

2010-08-03 Thread Rory Campbell-Lange
On 03/08/10, Alex Willmer (a...@moreati.org.uk) wrote: > On Aug 3, 11:21?am, loial 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

Re: Get name of file from directory into variable

2010-08-03 Thread loial
On 3 Aug, 11:31, Alex Willmer wrote: > On Aug 3, 11:21 am, loial 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? > >

Re: Get name of file from directory into variable

2010-08-03 Thread Matteo Landi
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. Regards. [1] http://docs.python.org/library/os.html?highlight=os.walk#os.walk On Tue, Aug 3, 2010 at

Re: Get name of file from directory into variable

2010-08-03 Thread Alex Willmer
On Aug 3, 11:21 am, loial 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

Get name of file from directory into variable

2010-08-03 Thread loial
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? -- http://mail.python.org/mailman/listinfo/python-list