Find and copy files to existing Folders with corresponding names in python
Question: i have a large number of files that i need to move to a specific existing
folder. the problem is that the number code that relates the file and the
folder has text on either side of it as shown below the number code is a071137
in the file name and A071137 in the folder name.

for example, i need to move file: "a071137_gindalbie.pdf" to folder "A071137
2006 Teck Commginco Pty Ltd" .

I would like to do this using python

I guess I first find the corresponding file using glob? Then to copy it there
?? not sure??


Answer: Your question is rather vague, but hopefully I can at least point you in the
right direction here. Sounds like you will want to be able to list all of the
files in a directory, which can be done with `os.listdir(directory)` as
described in the [api](http://docs.python.org/library/os.html). You will
likely then iterate through these files, and extract the relevant information
you will need using a regular expression. You'll need to reference [the
api](http://docs.python.org/library/re.html) on that too. For example, you can
extract a number using something like:

    
    
    >>> import re
    >>> r = re.compile('^a(?P<id>[0-9]+)')
    >>> m = r.match('a123')
    >>> m.group('id')
    '123'
    

Next you can move files using things in the `shutil` module. You should be
able to use `shutil.move()` for your purposes. For more information, again,
checkout [the api](http://docs.python.org/library/shutil.html).

