finding an exact match of filenames

jimgardener jimgardener at
Sat Oct 16 10:31:35 CEST 2010

I am trying to code a function that takes a directory name and a name
string and try to return a list of fully qualified names of all files
in the directory having an exact match of name.

I have these files in the directory,

When I call
get_filenames('mydir', 'googlegroup_python' )

I expect to get a list like
['/mydir/googlegroup_python__111.txt', '/mydir/

but not the other three.

I was careless when I coded the method as

def get_filenames(dirname,filenamestr):
    match_filenames=[dirname+os.sep+x for x inos.listdir(dirname) if
    return match_filenames

because this would return all 5 of the above filenames.I think reg
expression maybe the way to do this..but not very sure as to how I can
do it..

Any help or suggestions greatly appreciated

More information about the Python-list mailing list