Question: I am trying to create a python script that can receive multiple files as input through a command line.

Right now I am working with a method of using one file as input:

I would presently call the function using: `python function_name.py input_file.txt`

Using code that looks like this:

```
import sys
def function_name(): 
    input = sys.argv[1]
    with open(input,'r') as afile:
        read_data = afile.read()
if __name__ == '__main__':
    function_name()

```

But how can I use all of the .txt files in the current directory as input?

i.e.: `python function_name.py *.txt`
OR: `python function_name.py ./*/*.txt`

I would like to perform the same actions on each input file.

Answer: 
sys.argv is a list of arguments passed to the script. The first will be the name of the script (scriptname.py), and the rest will be whatever you type after it.

If you run `python function_name.py *.txt`, this will be expanded by the shell, to `python function_name.py 1.txt 2.txt blah.txt wibble.com.exe.extension.txt` (or whatever filenames you have in this directory.

So, I would do something like this:

```
 def function_name(): 
      for filename in sys.argv[1:]:
          print "You specified %s on the commandline - do something with it here!" % filename

```

The `[1:]` part means, ignore any parameters before index 1 (i.e. start at the second), or you will be processing your python script!

As a rule of thumb, I would probably pass this as a parameter to the function, so:

```
import sys
def function_name(filestoprocess): 
    for input in filestoprocess:
        print "Processing %s" % input
        with open(input,'r') as afile:
            read_data = afile.read()
if __name__ == '__main__':
    function_name(sys.argv[1:])

```
You might want to check out the [glob](https://docs.python.org/2/library/glob.html) module. You could feed your command line into `glob.glob`, and it will give you a list of files matching the wildcards you sent in. Then you can work on them as you see fit