Newbie problem with user input

Simon Brunning SBrunning at trisystems.co.uk
Wed Jul 11 10:03:43 EDT 2001


> From:	Chris McMillan [SMTP:christopherjmcmillan at eaton.com]
> Hello all!  The partial code below prompts a user to enter a path.  I then
> want it to find (and later do something with) all the files in that
> directory matching the specified string.  The problem is that when I run
> the
> script, and enter, for example D:\test it does not find any of the files.
> I
> believe it is because the glob command is searching for
> ''D:\\test'\\*.dat'
> With the extra single quotes.  How can I get it to search for
> 'D:\\test\\*.dat' ?  Thanks!
> Chris
> 
> print 'Enter the path:'                  # prompt user for directory path
> path = raw_input()
> for fname in glob.glob('path\\*.dat'):   # finds files matching string
 
Try this (untested):

import os, glob

path = raw_input('Enter the Path')
for fname in glob.glob(os.path.join(path, '*.txt')):
    pass # do whatever...

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list