Question: I have a folder `/image/` that has the following files: 
`1.jpg, 2.jpg, 5.jpg`

And a list:

```
img = [1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg]

```

How do I compare the list and the directory contents to find out that `3.jpg` and `4.jpg` files are missing?

I searched online but the only solutions I found show how to compare list to list or directory to directory.

Answer: 
To search for files in a directory, you can use [`glob`](http://docs.python.org/2/library/glob.html), like this:

```
import glob

dir_to_search = '/some/path/to/images/'

files_in_dir = glob.glob("{}{}".format(dir_to_search,'*.jpg'))

list_of_files = ['1.jpg','2.jpg','3.jpg']

missing_files = [x for x in list_of_files if x not in files_in_dir]

```
```
import os
path= r"C:\yourdirectory"  
fileList = os.listdir(path)

img = [...]
missing = [name for name in img if name not in fileList]

```

If order is not important you can use sets instead

```
import os
path= r"C:\yourdirectory"  
fileSet = set(os.listdir(path))

img = [...]
missing = set(img)-fileSet

```