Question: I am trying to write a python script to save me time copy/pasting updated files. 

This is what i got so far:

```
import os
import shutil

src_files = [
    'C:/orig/path/to/some/file/module_some_file.php',
    'C:/orig/path/to/some/other/file/module_some_file.php',
    'C:/orig/path/to/some/third/file/module_with_diff_name_after_module.php',
    # ....
]

dest_files = [
    'C:/copy/path/to/some/file/module_some_file.php',
    'C:/copy/path/to/some/other/file/module_some_file.php',
    'C:/orig/path/to/some/third/file/module_with_diff_name_after_module.php',
    # ....
]

for i in range(len(src_files)): 
  FILE_DIR=os.path.dirname(dest_files[i])
  if not os.path.exists(FILE_DIR):
    os.makedirs(FILE_DIR)
  if (os.path.isfile(src_files[i])):
    shutil.copy(src_files[i], dest_files[i])

```

This way works but i would like to achieve that i enter for example `py copy.py module --src "C:/orig/path/to/some" --dest "C:/copy/path/to/some"` and the script will search all files where name contains "module". A wildcard kind of solution. **My question(s), can i achieve what i want with python? And can someone help me with substituting the lists for some elegant wildcard/search solution?**

Environment: Windows / python 3.6.1

This is literally my first python script so please have some mercy :)

Answer: 
You can do so using `glob` to search all files with a certain name. Here's an example:

```
import shutil
import glob, sys, os

src_files = glob.glob1(sys.argv[3], '*%s*'%sys.argv[1])
dest = sys.argv[5]
for name in src_files:
    shutil.copy(os.path.join(sys.argv[3], name), os.path.join(dest, name))

```

`py modulename.py module --src "C:/orig/path/to/some" --dest "C:/copy/path/to/some"`

To improve this code, you can use argparse instead of sys.argv.

Here's a more professional way:

```
import shutil, argparse
import glob, os

parser = argparse.ArgumentParser()
parser.add_argument('name', metavar='N', type=str, nargs='+')
parser.add_argument('--src', required=False)
parser.add_argument('--dest',  required=False)
parsed = parser.parse_args()

src_files = glob.glob1(parsed.src, '*%s*'%parsed.name[0])
dest = parsed.dest
for name in src_files:
    shutil.copy(os.path.join(parsed.src, name), os.path.join(dest, name))

```

Like all other command calling, you will need to use the `=` when calling: 
`py modulename.py module --src="C:/orig/path/to/some" --dest="C:/copy/path/to/some"`
Based on the comments and answers, i have rewritten the script to following:

```
import argparse, shutil, glob, sys, ntpath, os

def parse_args():
    # Set up the parser, and tell it what arguments to expect
    parser = argparse.ArgumentParser()
    parser.add_argument('--search')
    parser.add_argument('--src')
    parser.add_argument('--dest')
    # Get the list of arguments from the command line, starting from
    # index 1 (since index 0 is the name of this file).
    raw_args = sys.argv[1:]
    # Parse the args, and return the object containing them
    args = parser.parse_args(raw_args)
    return args

args = parse_args()

for filename in glob.iglob(args.src+'/**/*'+args.search+'*', recursive=True):
    src_file = os.path.join(args.src, filename)
    dest_file = filename.replace(args.src,args.dest)
    dest_dir = os.path.dirname(dest_file)
    if os.path.isdir(src_file):
        continue
    if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)
    if (os.path.isfile(src_file)):
        shutil.copy(src_file, dest_file)

```

Now i can do this:

```
py copy_files.py --search "searchterm" --src "C:/orig/path/to/some" --dest "C:/copy/path/to/some"

```

After the edit of [abccd](https://stackoverflow.com/users/6622817/abccd) i suppose i can still improve these lines:

```
for filename in glob.iglob(args.src+'/**/*'+args.search+'*', recursive=True):
    src_file = os.path.join(args.src, filename)
    dest_file = filename.replace(args.src,args.dest)
    dest_dir = os.path.dirname(dest_file)

```