Matching filename and saving it to a variable in python
Question: Does anyone know how to match a filename and then saving it to a variable?

For instance I've got multiple files that are being saved in one folder. All
of them start with the same name. "AmountFile" all of them start with but then
they differ in filename rest of the filename is date.

So all look like AmountFile in the begining but then AmountFile20141020 and so
on.

I want to match the filename save it in a variable so I can use it in a
os.rename function.

    
    
    File1 = AmountFile123
    File2 = AmountFile321
    File3 = AmountFile456
    File4 = AmountFile789
    

I want to match them so I can use it in a variable.

    
    
    def main():
    d = 'D:\Applications\IMP\Something'
    for filename in os.listdir(d):
        title = 'Import_ABC'
        oldFile = 'AmountFile'
        if filename.endswith(".csv"):
            os.rename(oldFile,title+".csv")
    
    main()
    
    WindowsError: [Error 2] The system cannot find the file specified
    

My system will when finished rename files in the folder automatically move
them to another folder from where they will be imported to our database.
Problem is as in the example files have the same start but end differently
which is making it hard to run the function. For the OldFile variable I need
to match a file name which can be saved instead of 'AmountFile'


Answer: 
    import glob
    
    filenames = glob.glob("AmountFile*")
    

`filenames` will then be a list of all files in the current directory whose
names start with `AmountFile`.

