how to match file name in the file using python
Question: How to find out if two file exists with same pattern inside a file.If all
filenames have two-set of filenames ( csv.new and csv) then go ahead to next
step otherwise exit with error message.

The prefix "abc_package" will have two files one with extension "csv.new" and
second file with extension "csv". There could be many filenames inside the
"list_of_files.txt".

Ex: List_of_files.txt

    
    
    abc_package.1406728501.csv.new
    abc_package.1406728501.csv
    abc_package.1406724901.csv.new
    abc_package.1406724901.csv
    


Answer: For matching the file name name in python you can use
[fnmatch](https://docs.python.org/2/library/fnmatch.html) module..I will
provide you a sample code from the documentation.

    
    
    import fnmatch
    import os
    
    for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*.txt'):
        print file
    

The syntax would be `fnmatch.fnmatchcase(filename, pattern)`

Please have a look [here](https://docs.python.org/2/library/fnmatch.html) for
more examples

