How to search the entire HDD for all pdf files?
<p>As the title suggests, I would like to get python 3.5 to search my root ('C:\')
for pdf files and then move those files to a specific folder.
This task can easily split into 2: 
1. Search my root for files with the pdf extension.
2. Move those to a specific folder.</p>

<p>Now. I know how to search for a specific file name, but not plural files that has a specific extension. </p>

<pre><code>import os

print('Welcome to the Walker Module.')
print('find(name, path) or find_all(name, path)')

def find(name, path):
for root, dirs, files in os.walk(path):
    print('Searching for files...')
    if name in files:
        return os.path.join(root, name)

def find_all(name, path):
result = []
for root, dirs, files in os.walk(path):
    print('Searching for files...')
    if name in files:
        result.append(os.path.join(root, name))
return result
</code></pre>

<p>This little program will find me either the 1st or all locations of a specific file. 
I, however, can not modify this to be able to search for pdf files due to the lack of knowledge with python and programming in general.</p>

<p>Would love to have some kind of insight on where to go from here. </p>

<p>To sum it up, </p>

<ol>
<li>Search the root for all pdf files. </li>
<li>Move those files into a specific location. Lets say 'G:\Books'</li>
</ol>

<p>Thanks in advance. </p>

<p>Your find_all function is very close to the final result.
When you loop through the files, you can check their extension with os.path.splitext, and if they are .pdf files you can move them with shutil.move</p>

<p>Here's an example that walks the tree of a source directory, checks the extension of every file and, in case of match, moves the files to a destination directory:</p>

<pre><code>import os
import shutil


def move_all_ext(extension, source_root, dest_dir):
    # Recursively walk source_root
    for (dirpath, dirnames, filenames) in os.walk(source_root):
        # Loop through the files in current dirpath
        for filename in filenames:
            # Check file extension
            if os.path.splitext(filename)[-1] == extension:
                # Move file
                shutil.move(os.path.join(dirpath, filename), os.path.join(dest_dir, filename))


# Move all pdf files from C:\ to G:\Books
move_all_ext(".pdf", "C:\\", "G:\\Books")
</code></pre>

python windows python-3.x